For loop stops in the first find

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by