Count number of indexes for each consecutive values in column of array

1 次查看(过去 30 天)
I have an array of a variable of dimension: 23999 x 1
The array consists of 1s and 0s.
I want to count how many indexes each consecutive 1s take up. For example:
[0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0] (vertically of course)
the output I would like is 3 9
I tried using diff and find but keep getting the error horzcat... Can somebody help me?

采纳的回答

Stephen23
Stephen23 2020-8-3
>> V = [0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0];
>> D = diff([0;V(:);0]);
>> find(D<0)-find(D>0)
ans =
3
9

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by