Uninterrupted segment length?
Afficher commentaires plus anciens
Let's say I have an array indexes:
Indexes = [1122221122111211112222222]
How do I get the length of uninterrupted 2s? I want to output to be
output=[ 4 2 1 7]
Réponse acceptée
Plus de réponses (1)
Roger Stafford
le 28 Nov 2016
Modifié(e) : Roger Stafford
le 28 Nov 2016
f = find(diff([false,Indexes==2,false])~=0);
output = f(2:2:length(f))-f(1:2:length(f));
1 commentaire
Qisq
le 27 Avr 2018
Very elegant solution. Thanks.
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!