フィルターのクリア

How to delete a row from an array if a specified column has specified numbers?

1 回表示 (過去 30 日間)
L'O.G.
L'O.G. 2022 年 3 月 30 日
コメント済み: L'O.G. 2022 年 3 月 30 日
I want to delete a row from an array if a specified column has a specified number. How do I generalize the following if there is more than one number specified, i.e., for a vector with arbitrary length? The following does what I want for the specified numbers 5 and 6 and column 2, but I want to generalize it.
A(((A(:,2) == 5) | (A(:,2) == 6)),:) = [];

採用された回答

Kevin Holly
Kevin Holly 2022 年 3 月 30 日
A = round(10*rand(20,3))
A = 20×3
7 5 1 2 9 3 4 9 4 1 8 0 8 10 9 3 7 4 5 7 7 8 5 1 2 8 0 3 10 5
for n = [5,6]
A((A(:,2) == n),:) = [];
end
A
A = 17×3
2 9 3 4 9 4 1 8 0 8 10 9 3 7 4 5 7 7 2 8 0 3 10 5 5 10 0 2 0 4
  1 件のコメント
L'O.G.
L'O.G. 2022 年 3 月 30 日
Thank you! Ugh, I should've seen this way. I appreciate your help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by