Join repeated continuous elements of a vector
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Hi, is there a simple method to join repeated continuous elements of a vector in Matlab?
For example if the input is:
in = [1 1 1 2 2 3 6 6 6 1 1 1 4 4 4 2 2 2 6 4 4]
how can i get
out = [1 2 6 1 4 2 6 4]
Note that since 3 is not repeted, it is not in 'out' vector. Same for the only 6.
thanks !
2 comentarios
Walter Roberson
el 27 de Feb. de 2020
No, there is no simple method. There are some methods that take a few lines.
Alexander
el 27 de Feb. de 2020
Respuestas (1)
Are Mjaavatten
el 27 de Feb. de 2020
in = [1 1 1 2 2 3 6 6 6 1 1 1 4 4 4 2 2 2 6 4 4];
i = 1;
count = 1;
out = [];
a = in(1);
while i < length(in)
i = i+1;
if in(i) ~= a
count = 1;
a = in(i);
else
count = count + 1;
end
if count == 2;
out = [out,a];
end
end
disp(out)
1 comentario
Alexander
el 27 de Feb. de 2020
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!