how can I find the max value out of iterative for loop ?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
omar th
el 1 de Ag. de 2022
Comentada: Matt J
el 1 de Ag. de 2022
here, the problem is when, for loop iterate itself let's say 5 times, the first maxvalue from is 9, the second is 3, the third is 5, the fourth is 7 and the fifth is 3, so the max_maxvalue (global max) must be 9 out of these five iterations. But I got 3 as max_maxvalue (global max) which means its chose the max value from the last iteration NOT saving the previous max values and compare among them according to what I want.
Thanks in advance for any help
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);
0 comentarios
Respuesta aceptada
Matt J
el 1 de Ag. de 2022
Seems to be working:
count=1;
while 1
for i=1:20
x(i)= randi(87);% calculations
end
maxvalue(count) = max(x);
count=count+1;
if x(end) == maxvalue(end)
break
end
end
maxvalue
max_maxvalue=max(maxvalue)
2 comentarios
Matt J
el 1 de Ag. de 2022
But as you can see in my RUN above, we did get a max_maxvalue of 86, as you desired.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!