Find min and max value of vector without using built-in function
Afficher commentaires plus anciens
Hello, I know that this question has been already asked many times, however, I kind of struggle to execute it. Max shows correct result, but the not the minimum value. What could be the solution?
A = [9 6 8 3 6 8 2 1 3 9 1 0 2]
maxval = A(1);
minval = 1;
for i = 1:length(A)
if A(i) > maxval
maxval = A(i);
else A(i) < minval
minval = A(i)
end
end
Réponse acceptée
Plus de réponses (1)
Matt J
le 19 Sep 2022
%maxval = A(1);
%minval = 1;
maxval = -inf;
minval = +inf;
Catégories
En savoir plus sur Performance and Memory dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!