Loop for removing values from a column vector
Show older comments
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 Comment
Nikita Kaminskyy
on 10 Dec 2020
Edited: Nikita Kaminskyy
on 10 Dec 2020
Accepted Answer
More Answers (1)
Fangjun Jiang
on 10 Dec 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 Comment
Nikita Kaminskyy
on 10 Dec 2020
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!