Keeping count of consecutive of two vectors

1 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2016-2-17
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.

请先登录,再进行评论。

回答(1 个)

Jos (10584)
Jos (10584) 2016-2-17
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))

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by