Loop for removing values from a column vector
显示 更早的评论
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 个)
Fangjun Jiang
2020-12-10
%%
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
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!