Uninterrupted segment length?
古いコメントを表示
Let's say I have an array indexes:
Indexes = [1122221122111211112222222]
How do I get the length of uninterrupted 2s? I want to output to be
output=[ 4 2 1 7]
採用された回答
その他の回答 (1 件)
Roger Stafford
2016 年 11 月 28 日
編集済み: Roger Stafford
2016 年 11 月 28 日
f = find(diff([false,Indexes==2,false])~=0);
output = f(2:2:length(f))-f(1:2:length(f));
1 件のコメント
Qisq
2018 年 4 月 27 日
Very elegant solution. Thanks.
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!