How can I find the max value from many max values inside the " WHILE LOOP " ?
이전 댓글 표시
if we run the code below we will get the maxpower in each round of "for loop" means the for loop starts from -28.64 up to +28.64 which means
20 steps. Now, the maxpower is obtained from each round (20 steps of the for loop). My question is how can I find the maximum value from many maxpower values inside while loop ?
Thanks in advance
Angleoption11 = [-28.6479 -27.5 -18.33 -13.75 -11 -9.16 -7.85 -6.87 -6.11 -5.5 5.5 6.11 6.87 7.85 9.16 11 13.75 18.33 27.5 28.6479];
while true
previouspower = currentpower;
for current_index1 = 1:numel(Angleoption11)
pickangle11 = Angleoption11(current_index1);
distance = sqrt((x1-x2.').^2 + (y1-y2.').^2)
currentpower=pt*distance
end
[maxpower, index]=max(currentpower);
end
댓글 수: 4
James Tursa
2022년 7월 26일
편집: James Tursa
2022년 7월 26일
It is unclear what this code does or is intended to do. E.g.,
- There is no break out of the forever while loop, so the code will never terminate on its own
- previouspower is never used
- pickangle11 is never used
- The distance calculation doesn't depend on anything in the loop
- pt is not defined anywhere
- x1, x2, y1, y2 are not defined anywhere
- Etc.
It is impossible to advise you how to get your desired result when your code does not appear to be a minimal working example. Or maybe you could use some numeric example inputs and show us what your desired numeric outputs would be.
omar th
2022년 7월 26일
dpb
2022년 7월 26일
Save the max you find each iteration in another array -- when the outer iteration is complete, then use max on that array.
Or, you can compare the new maximum to the previous each time and save the greater on each pass -- to do this you also must have a GlobalMax value that starts of first iteration holding the maximum; for subsequent does the comparison first.
omar th
2022년 7월 26일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!