Length of runs of same number in an array

15 vues (au cours des 30 derniers jours)
dan berkowitz
dan berkowitz le 5 Nov 2017
Commenté : dan berkowitz le 5 Nov 2017
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

Réponse acceptée

Stephen23
Stephen23 le 5 Nov 2017
Modifié(e) : Stephen23 le 5 Nov 2017
>> V = [-1,-1,0,0,0,-1,1,-1,1,1];
>> diff(find([1,diff(V),1]))
ans =
2 3 1 1 1 2

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by