Plot not showing a line, only individual points(one at a time)?

3 ビュー (過去 30 日間)
Evan Mossel
Evan Mossel 2018 年 7 月 23 日
編集済み: Geoff Hayes 2018 年 7 月 24 日
When I graph my plot, I used the drawnow function and it would plot individual points, then move on to the next without saving the previous point or drawing a line. Any suggestions?
altmax=-inf;
days=10;
dy=-1;
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);
xplot=dy;
yplot=alt;
plot(xplot,yplot,'-o');
drawnow
end

採用された回答

Geoff Hayes
Geoff Hayes 2018 年 7 月 23 日
Evan - with each call to plot, you are creating a new plot graphics object. Since you are not calling hold on, then all previously drawn graphics objects will be removed. So you could add a hold on statement to fix this problem or, rather than creating dozens (or more?) plot graphics objects, just keep re-using the existing one.
altmax=-inf;
days=10;
dy=-1;
hPlot1 = plot(NaN,NaN); % create a plot graphics object with handle hPlot1
while dy<=days
% your code
% when ready to plot the data...
xdata = get(hPlot1,'XData');
ydata = get(hPlot1,'YData');
set(hPlot1,'XData',[xdata dy],'YData',[ydata alt]);
drawnow;
end
So when you have calculated dy and alt, we get the current set of XData and YData from the plot graphics object and then update it with the new data points. Try the above and see what happens!
  3 件のコメント
Evan Mossel
Evan Mossel 2018 年 7 月 23 日
What does NaN mean in this instance?
Geoff Hayes
Geoff Hayes 2018 年 7 月 24 日
編集済み: Geoff Hayes 2018 年 7 月 24 日
NaN is just "not a number" (see NaN for details).

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by