Filter löschen
Filter löschen

Keeping count of consecutive of two vectors

1 Ansicht (letzte 30 Tage)
Daniel
Daniel am 17 Feb. 2016
Kommentiert: Jos (10584) am 17 Feb. 2016
I have two vectors.
A = [9 9 8 12 12 12 7 6 15 15 15 15 21 21 10 5 15 9 9 9 9 7 20 20 1 5 6 7 7];
B = [212 100 212 200 180 200 134 150 200 200 200 200 150 120 120 120 120 120 120 212 212 212 150 150 150 120 133 132 123 150];
I need to count how many times A == 9 && B >= 212 consecutively. As well as count 10 =< A < 15 && B >= 200 consecutively, and count where A>=15 && B>= 150 consecutively.
I'd appreciate any help.
  2 Kommentare
Stephen23
Stephen23 am 17 Feb. 2016
The vectors A and B have different number of elements, therefore it is not possible to merge their logical relations like this: A == 9 & B >= 212.
Can you please show us the exact output that you expect for these input vectors.
Jos (10584)
Jos (10584) am 17 Feb. 2016
Well spotted, Stephen!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jos (10584)
Jos (10584) am 17 Feb. 2016
I am not really sure what you mean by consecutively. But this may help you further:
TF = A ==9 && B>= 212
will give you a sequence of true (1) and false (0). If you want to count how many times a true is followed by another true in TF.
MyCount = sum(TF(1:end-1) & TF(2:end))

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by