MATLAB: Delete Rows that have a negative number in their first column.

conditional deletion of matrix rows or columnsdelete rows

Hi, I have a 5×2 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.

Best Answer

A=[-1 2;2 -4;-5 9;-3 7;8 6]
%find the rows that we don't want, remove them and show the rest
A(A(:,1)<0,:)=[]
another way
A(A(:,1)>=0,:) %find and show only the rows that we want