Keeping count of consecutive of two vectors
1 view (last 30 days)
Show older comments
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 Comments
Stephen23
on 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.
Answers (1)
Jos (10584)
on 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))
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!