Count total number of recurring sequences

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

 Réponse acceptée

If you get RunLength from the FileExchange this is fairly easy:
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))
counts = 1×4
3 0 1 2
output=[ ( 1:max(N) ).' counts.'];
disp(output)
1 3 2 0 3 1 4 2

Plus de réponses (0)

Produits

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by