How to return the maximum value of a vector without using the built in function max(x)?
Afficher commentaires plus anciens
I have to calculate the maximum value of a vector, x, without using the built in function, only using basic mathematical,
relational, and logical operations. Then the maximum must be stored to a variable, y. The script must work with any vector assigned to x.
Réponses (2)
Star Strider
le 30 Avr 2019
0 votes
Apparently, you also cannot use a built-in sort algorithm. That leaves you the option of coding your own bubble-sort algorithm, or the Quicksort (link) algorithm.
KSSV
le 30 Avr 2019
K = rand(5) ;
themax = -Inf;
row = 0;
column = 0;
for i = 1:size(K, 1)
for j = 1:size(K, 2)
if K(i, j) > themax
themax = K(i, j);
row = i;
column = j;
end
end
end
Catégories
En savoir plus sur R Language 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!