フィルターのクリア

Delete rows for specific elements from a matrix

1 回表示 (過去 30 日間)
Lily
Lily 2013 年 9 月 20 日
Hi
I'm trying to delete all rows if the second and third element is equal to zero. My if-else sentence doesn't work. Could you help me?
f = [2 5 4 3 2; 4 9 2 1 9; 2 0 0 0 0; 4 0 0 0 3; 9 7 12 14 42];
for i = 1:length(f)
if (f(i,2) == 0) && (f(i,3) == 0)
f(i,:) = [];
end
end
A = f; % Want the final result of A to look like this: A = [2 5 4 3 2; 4 9 2 1 9; 9 7 12 14 42]
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 20 日
The problem is with for i = 1:length(f), because f(i,:) = [] will decrease the length of f

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 20 日
編集済み: Azzi Abdelmalek 2013 年 9 月 20 日
f = [2 5 4 3 2; 4 9 2 1 9; 2 0 0 0 0; 4 0 0 0 3; 9 7 12 14 42];
f(all(~f(:,2:3),2),:)=[]
%or
f=f(any(f(:,2:3),2),:)
  1 件のコメント
Lily
Lily 2013 年 9 月 20 日
Really nice!! Thank you :)

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

その他の回答 (0 件)

カテゴリ

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