how can we use max function inside while loop ?

6 Ansichten (letzte 30 Tage)
omar th
omar th am 29 Jul. 2022
Kommentiert: omar th am 1 Aug. 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

Akzeptierte Antwort

David Hill
David Hill am 29 Jul. 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 Kommentare
omar th
omar th am 30 Jul. 2022
It's woked, thank you so much
omar th
omar th am 1 Aug. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by