how can I delete some rows from 2-D array?

2 ビュー (過去 30 日間)
Aniee  Shah
Aniee Shah 2017 年 5 月 27 日
コメント済み: Aniee Shah 2017 年 5 月 27 日
I have a 2d array of 2x1500 i want to delete those rows which contain 0 in their first column. If someone knows how to do this plz tell me .

採用された回答

Stephen23
Stephen23 2017 年 5 月 27 日
編集済み: Stephen23 2017 年 5 月 27 日
Where M is your matrix:
newmat = M(M(:,1)~=0,:)

その他の回答 (1 件)

MathReallyWorks
MathReallyWorks 2017 年 5 月 27 日
Hello Aniee,
I tried this, it works as per your requirement.
copy and paste this in command window:
A=[ 0 2; 2 3; 0 5; 6 0; 7 8; 8 0; 9 1]
A =
0 2
2 3
0 5
6 0
7 8
8 0
9 1
Now, copy and paste this in command window:
%I have taken only 7 rows. You can do this for 1500 rows. It works exactly the same way.
for i=1:7
if A(i,1) == 0
A(i,:) = [];
end
end
Now type A in command window:
A =
2 3
6 0
7 8
8 0
9 1
You can see the difference.
I hope it will be helpful.
  1 件のコメント
Aniee  Shah
Aniee Shah 2017 年 5 月 27 日
thanks alot

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by