Create vector only containing consecutive numbers of other vector
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Janina Koussev
el 30 de Mzo. de 2015
Comentada: Star Strider
el 31 de Mzo. de 2015
Hi, I'm searching for a possibility to build a vector B which only contains the consecutive numbers of vector A. I tried it like this but it is not working. Can someone help me?
A=[2 5 6 7]; B=0; for m=1:length(A)-1 if diff(A)==1 B=A(m); m=m+1; end end
The anwser should look like this: B=[5 6 7]
0 comentarios
Respuesta aceptada
Más respuestas (1)
Stephen23
el 30 de Mzo. de 2015
>> A = [2,5,6,7];
>> X = diff(A)==1;
>> Y = [false,X] | [X,false];
>> A(Y)
ans =
5 6 7
6 comentarios
Star Strider
el 31 de Mzo. de 2015
I delete my Answers if they are neither Accepted nor Voted. Many others do as well.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!