Count total number of recurring sequences
1 view (last 30 days)
Show older comments
I would like to count how many times a consecutive sequence occurs in a list.
Let's say I have [0;1;1;1;0;0;0;0;1;0;1;1;1;1]
The output would be
1 3
2 0
3 1
4 2
0 Comments
Accepted Answer
Rik
on 17 May 2021
data=[0;1;1;1;0;0;0;0;1;0;1;1;1;1];
[~,N] = RunLength_M(data);
counts=histcounts(N,0.5:(max(N)+0.5))
output=[ ( 1:max(N) ).' counts.'];
disp(output)
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!