how can we use max function inside while loop ?

6 visualizzazioni (ultimi 30 giorni)
My question, can we choose the maximimum value out of the maxvalue as explained below the first maxvalue 4 the second maxvalue 8, the third maxvalue 3 the fourth maxvalue 2 and the fifth max value is 6. ??
thanks in advance
while true
for i=1:20
x= do calculation from 1 up to 20 % (1:20= we call it one round)
end
[maxvalue(i), indxmax] = max(x(:));
maxvalue will be one value in each for loop round, but for loop will be repeated let say 5 times
so, maxvalue will be 4 in first 20 step, 8 in the second 20, 3 in third round, and so forth
up to 5 round
if x(i) >= maxvalue(i) % This condition to break the while loop
break
end
end

Risposta accettata

David Hill
David Hill il 29 Lug 2022
count=1;
while 1
for i=1:20
x(i)= % calculations
end
maxvalue(count) = max(x);
count=count+1;
if x(end) == maxvalue(end)
break
end
end
max_maxvalue=max(maxvalue);
  2 Commenti
omar th
omar th il 30 Lug 2022
It's woked, thank you so much
omar th
omar th il 1 Ago 2022
David Hill , please would you tell how can I find the global max. For example, if we for loop iterate its self 5 times, so, maxvalue from these iteration is 8, 3, 4, 5,6, here the max_maxvalue consider only the last maxvalue as max_maxvalue not compare among the max value og the 5 iterations and consider 8 as the max_maxvalue, I dont know to make that

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by