Uninterrupted segment length?
Mostrar comentarios más antiguos
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]
Respuesta aceptada
Más respuestas (1)
Roger Stafford
el 28 de Nov. de 2016
Editada: Roger Stafford
el 28 de Nov. de 2016
f = find(diff([false,Indexes==2,false])~=0);
output = f(2:2:length(f))-f(1:2:length(f));
1 comentario
Qisq
el 27 de Abr. de 2018
Very elegant solution. Thanks.
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!