For loop stops in the first find

3 ビュー (過去 30 日間)
Fil Okua
Fil Okua 2021 年 4 月 25 日
編集済み: Walter Roberson 2021 年 4 月 25 日
Why does this for loop stop at the first find?.
Val = max(max(D(:, 2:end), [], 2));
rows = [];
for i = 1:size(D, 1)
if (any(D(i, 2:end) == Val))
rows = [rows, i];
D(rows)
end
end
  5 件のコメント
Fil Okua
Fil Okua 2021 年 4 月 25 日
@Image Analyst, I am trying store both.
Fil Okua
Fil Okua 2021 年 4 月 25 日
But I'm only interested in the values at the indexes

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 25 日
編集済み: Walter Roberson 2021 年 4 月 25 日
Val = max(max(D(:, 2:end), [], 2));
rows = [];
for i = 1:size(D, 1)
if (any(D(i, 2:end) == Val))
rows = [rows; D(i,:)];
end
end
However...
mask = any(D == max(max(D(:,2:end))),2);
rows = D(mask,:);
with no loop is all that is needed.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by