Count number of indexes for each consecutive values in column of array
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Stephen23
le 3 Août 2020
>> 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!