필터 지우기
필터 지우기

Obtain maximum value of variable over multiple iterations?

조회 수: 2 (최근 30일)
Evan Mossel
Evan Mossel 2018년 7월 20일
댓글: James Tursa 2018년 7월 20일
I plan to run my code several times using a loop and want to record the maximum value of the variable 'alt.' How would I go about doing this?
%
yr=2018;
mnth=7;
dy=0:31;
hr=0;
min=0;
sc=0;
d=datetime(yr,mnth,dy,hr,min,sc);
JD_TT=juliandate(d);
CooType='q2000';
[X,Y,Z]=moonpos(JD_TT,CooType);
[lat,lon,alt]=ecef2lla(X,Y,Z);
end

채택된 답변

James Tursa
James Tursa 2018년 7월 20일
편집: James Tursa 2018년 7월 20일
E.g., you could add a variable to your looping for this:
altmax = -inf;
% your loop start
% stuff that calculates alt
altmax = max([alt altmax]);
% your loop end
Or you could store all of the alt values in a vector and then take the max of that vector after the loop.
  댓글 수: 2
Evan Mossel
Evan Mossel 2018년 7월 20일
What does the -inf refer to?
James Tursa
James Tursa 2018년 7월 20일
Initial value of altmax set to minus infinity so that the code for recalculating altmax will work on the first iteration of the loop.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by