remove the rows of matrix?

4 ビュー (過去 30 日間)
jack nn
jack nn 2015 年 4 月 1 日
コメント済み: jack nn 2015 年 4 月 1 日
I want to remove the rows of matrix that the value of them in first column is zero...I use this code:
if true
for i=1:7
if m(i)==0
m(i,:)=[];
i=i-1;
end
end
end
I run this code for this matrix but the answer is not true,it could not remove all rows that the first column of them is zero..
if true
>> m=[1 2;3 4;0 5;3 0;0 4;0 54;3 22]
m =
1 2
3 4
0 5
3 0
0 4
0 54
3 22
if true
>> for i=1:7
if m(i)==0
m(i,:)=[];
i=i-1;
end
end
end
but when we saw the result,the result is: >> m
m =
1 2
3 4
3 0
0 54
3 22
end
is my cod wrong?

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 4 月 1 日
編集済み: Azzi Abdelmalek 2015 年 4 月 1 日
m=[1 2;3 4;0 5;3 0;0 4;0 54;3 22]
m(~m(:,1),:)=[]
  1 件のコメント
jack nn
jack nn 2015 年 4 月 1 日
thanks

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by