For loop stops in the first find
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Fil Okua
le 25 Avr 2021
Modifié(e) : Walter Roberson
le 25 Avr 2021
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 commentaires
Réponse acceptée
Walter Roberson
le 25 Avr 2021
Modifié(e) : Walter Roberson
le 25 Avr 2021
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!