For loop stops in the first find

조회 수: 5 (최근 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 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