Length of runs of same number in an array

13 ビュー (過去 30 日間)
dan berkowitz
dan berkowitz 2017 年 11 月 5 日
コメント済み: dan berkowitz 2017 年 11 月 5 日
Hi,
I have a 10x1 vector, a = [-1 -1 0 0 0 -1 1 -1 1 1].
How can I find the number of times a number occurs continuously (i.e. if the number is -1, how many times does it occur in a row.). I want my result matrix to be [2 3 1 1 1 2]
Any help would be appreciated! Thanks,
DB

採用された回答

Stephen23
Stephen23 2017 年 11 月 5 日
編集済み: Stephen23 2017 年 11 月 5 日
>> V = [-1,-1,0,0,0,-1,1,-1,1,1];
>> diff(find([1,diff(V),1]))
ans =
2 3 1 1 1 2
  1 件のコメント
dan berkowitz
dan berkowitz 2017 年 11 月 5 日
Much appreciated!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by