フィルターのクリア

Keeping count of consecutive of two vectors

1 回表示 (過去 30 日間)
Daniel
Daniel 2016 年 2 月 17 日
コメント済み: Jos (10584) 2016 年 2 月 17 日
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.
Jos (10584)
Jos (10584) 2016 年 2 月 17 日
Well spotted, Stephen!

サインインしてコメントする。

回答 (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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by