An important remark: my column_vector has values with several decimal places (10 or so), they're all double values
Loop for removing values from a column vector
9 views (last 30 days)
Show older comments
Nikita Kaminskyy
on 10 Dec 2020
Commented: Nikita Kaminskyy
on 10 Dec 2020
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
Accepted Answer
Cris LaPierre
on 10 Dec 2020
column_vector = [1 2 1 3 7 7 5 4 8 6 9 2];
logInd = [1 diff(column_vector)]>0; % Since diff will have n-1 values, prepend with 1
new_column_vector = column_vector(logInd)
6 Comments
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
See Also
Categories
Find more on Get Started with MATLAB 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!