フィルターのクリア

Count number of cells separating two trues in logical vector

1 回表示 (過去 30 日間)
Enrico Gambini
Enrico Gambini 2022 年 10 月 12 日
コメント済み: Enrico Gambini 2022 年 10 月 12 日
Hello!
I would like to find a fast procedure to count the number of cells separating two trues in a logical vector, and store the results in a new numeric vector.
For instance:
x=[true;false;false;false;true;false;false;true;false;true];
The output should be
output=[4;3;2]; % Hence, it counts also the "first" true
Hope the question is clear.
Thank you!

採用された回答

Matt J
Matt J 2022 年 10 月 12 日
x=[true;false;false;false;true;false;false;true;false;true];
diff(find(x))
ans = 3×1
4 3 2

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by