フィルターのクリア

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

14 ビュー (過去 30 日間)
Hajik zagori
Hajik zagori 2011 年 8 月 10 日
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.

採用された回答

Paulo Silva
Paulo Silva 2011 年 8 月 10 日
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

その他の回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 10 日
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
Hajik zagori 2011 年 8 月 10 日
Thanks Paulo and Fangjun. :X Both of your answers worked perfectly.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by