Loop for removing values from a column vector
Mostrar comentarios más antiguos
Hi all!
So I have a column vector that I imported from Excel spreadsheet with a certain amount of values (3000 something). What I'm trying to do is create a script with a loop that will go through every value in the vector and if the value of element k is <= than the value of element k-1, it deletes this value and goes to the next one.
Example: column_vector = [1 2 1 3 7 7 5 4 8 6 9 2] -------------> new_column_vector = [1 2 3 7 8 9]
Basicaly I want it to go up withou oscilating. Any help is appreciated (I havent touched Matlab for at least 5 years)
1 comentario
Nikita Kaminskyy
el 10 de Dic. de 2020
Editada: Nikita Kaminskyy
el 10 de Dic. de 2020
Respuesta aceptada
Más respuestas (1)
Fangjun Jiang
el 10 de Dic. de 2020
%%
v=[1 2 1 3 7 7 5 4 8 6 9 2];
for k=length(v):-1:2
if v(k)<=v(k-1)
v(k)=[];
end
end
1 comentario
Nikita Kaminskyy
el 10 de Dic. de 2020
Categorías
Más información sobre Creating and Concatenating 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!