how can we use max function inside while loop ?

조회 수: 6 (최근 30일)
omar th
omar th 2022년 7월 29일
댓글: omar th 2022년 8월 1일
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

채택된 답변

David Hill
David Hill 2022년 7월 29일
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
omar th
omar th 2022년 7월 30일
It's woked, thank you so much
omar th
omar th 2022년 8월 1일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by