Delete Rows that have a negative number in their first column.
Show older comments
Hi, I have a 5x2 matrix like this:
A=[-1 2;2 -4;-5 9;-3 7;8 6;]
Now I want a code to delete rows that have negative value in their first column. so the output will be this matrix: newA=[2 -4;8 6;]
tnx.
Accepted Answer
More Answers (2)
Fangjun Jiang
on 10 Aug 2011
A=[-1 2;2 -4;-5 9;-3 7;8 6;]
Index=A(:,1)<0;
NewA=A(~Index,:)
Or, a one-liner:
A=[-1 2;2 -4;-5 9;-3 7;8 6;]
A(A(:,1)<0,:)=[]
Hajik zagori
on 10 Aug 2011
0 votes
Categories
Find more on Operating on Diagonal 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!