What is an efficient way of finding the maximum value under a certain limit?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ali Almakhmari
le 23 Juil 2022
Réponse apportée : Torsten
le 23 Juil 2022
Can you guys throw few lines my way that will help me find the maximum value under a certain threshold in a matrix? Lets say I have this matrix: [1,2,3;4,5,6;7,8,9] and I would like to find the maximum value below 8, so the code will return the index and the value, which in this case will be the number 7. The reason I emphasized efficiency is because I will be running this so many times in a bunch of for loops, so I was looking for the fastest thing. Thanks in advance.
0 commentaires
Réponse acceptée
Torsten
le 23 Juil 2022
A = [1,2,3;4,5,6;7,8,9];
A(A>=8) = -Inf
[m,i] = max(A,[],'All')
[row,col] = ind2sub(size(A),i)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display 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!