What does this error mean?

1 回表示 (過去 30 日間)
Evan Mossel
Evan Mossel 2018 年 7 月 23 日
編集済み: Evan Mossel 2018 年 7 月 26 日
I keep getting the error: Subscript indices must either be real positive integers or logicals.
days=10;
dy=-1;
hPlot1 = plot(dy,alt);
while dy<=days
%--calculate & display current time (UTC)
yr=2018;
mnth=1;
dy=dy+1;
hr=0;
min=0;
sc=0;
d=datetime(yr,mnth,dy,hr,min,sc);
%d=datetime('now');
%--covert and display current time in julian days
JD_TT=juliandate(d);
%--convert julian days to moon position
CooType='q2000';
[X,Y,Z]=moonpos(JD_TT,CooType);
%plot3(X,Y,Z);
%--convert to LLA coordinates, in degrees
alt=sqrt(X.^2+Y.^2+Z.^2);
xdata = get(hPlot1,'XData');
ydata = get(hPlot1,'YData');
set(hPlot1,'XData',[xdata dy],'YData',[ydata alt]);
end
altmax=max(ydata);
xmax=find(alt==altmax);
altmin=min(ydata);
xmin=find(alt==altmin);
  15 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 24 日
Your xdata and ydata is going to include that initial nan value.
At the end of your loop, your xdata and ydata are not going to include the last dy and alt, because you change hPolt1's XData and YData after you assign to the temporary variable xdata and ydata.
Evan Mossel
Evan Mossel 2018 年 7 月 26 日
編集済み: Evan Mossel 2018 年 7 月 26 日
I changed the xdata/ydata to Xdata/Ydata but this did not resolve the issue.
Update: I misunderstood. This fixed the issue

サインインしてコメントする。

回答 (1 件)

Krithika A
Krithika A 2018 年 7 月 24 日
You use min in your code. min is already a matlab function
  5 件のコメント
Krithika A
Krithika A 2018 年 7 月 24 日
Not specifically for min/max. Min/max can handle non-integers. It would be another function.
Evan Mossel
Evan Mossel 2018 年 7 月 24 日
I believe it is the 'find' function. I will try to work it out.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by