Finding and deleting negative values

9 views (last 30 days)
I'm having trouble deleting negative values from a vector (vi) I wish to as an index:
vi =[-14:1:16];
I wrote this script:
l=length(vi); for i=1:l; while vi(i)<1; vi(i)=[]; break end end
Somehow, this only deletes the non-positive even numbered values in the matrix, not the negative ones (i.e. -14, -12, -10... disappear, but not -13, -11, -9)
Does anybody know why and can fix it for me?

Accepted Answer

Nellikin
Nellikin on 14 Feb 2012
found it: vi(vi<=0)=[];

More Answers (0)

Categories

Find more on Mathematics 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!