how can we use max function inside while loop ?

7 visualizaciones (últimos 30 días)
omar th
omar th el 29 de Jul. de 2022
Comentada: omar th el 1 de Ag. de 2022
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

Respuesta aceptada

David Hill
David Hill el 29 de Jul. de 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 comentarios
omar th
omar th el 30 de Jul. de 2022
It's woked, thank you so much
omar th
omar th el 1 de Ag. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by