Dynamic Plotting "Phantom" Line

5 次查看(过去 30 天)
Dear fellow MATLAB Users,
I have created a dynamic plotting system to be used with various x and y data points and have unwanted line appearing at the start of the plotting sequence. Here is my code as it currently stands:
__________ CODE START __________
x=[0;6;2;8;4;10;6;12;8];
y=[0;2;4;6;8;10;12;14;16];
t=numel(x);
r=x(t);
nnn=y(t);
s1=subplot(1,1,1);
set(s1,'xlim',[1 numel(x)],'ylim',sort([0 r]),'nextplot','add')
p1=plot(r,nnn,'r-');
p2=plot(r,nnn,'g*');
axis([0 20 0 20])
set(gca,'ydir','rev')
for t=1:numel(x)
r=x(t);
nnn=y(t);
set(p1,'xdata',[get(p1,'xdata') r],'ydata',[get(p1,'ydata') nnn])
set(p2,'xdata',r,'ydata',nnn)
pause(.5)
end
__________ CODE END __________
Notice how there is a line extending from the origin, to the final data point. I cannot understand why this is occurring, nor what to do to remedy it. Any help that could be lent to solve this issue would be greatly appreciated.
Thank you,
~ Chris
  2 个评论
Jan
Jan 2011-4-28
Please use the code formatting as described at the link called "Markup" on this page.
Chris Berry
Chris Berry 2011-4-28
I apologize, I am not able to find the "Markup" link on this page, nor through a site search. Would you please provide me with a link so that I can better submit questions and answers? Thanks.

请先登录,再进行评论。

采纳的回答

Paulo Silva
Paulo Silva 2011-4-28
Initialize p1 with this code
p1=plot(nan,nan,'r-');
instead of
p1=plot(r,nnn,'r-');
  1 个评论
Chris Berry
Chris Berry 2011-4-28
Exactly! Thank you, Paulo, for your help. It is people like you that make this forum great!

请先登录,再进行评论。

更多回答(1 个)

Jan
Jan 2011-4-28
You get a connection from the origin to the last data point, because your program explicitely instructs that.
x = [0;6;2;8;4;10;6;12;8];
y = [0;2;4;6;8;10;12;14;16];
t = numel(x);
r = x(t);
nnn = y(t);
s1 = axes('xlim',[0, 20],'ylim',sort([0 20]), ...
'nextplot','add', 'ydir','rev');
p1 = plot(r, nnn, 'r-');
p2 = plot(r, nnn, 'g*');
% Now [p1] is the last data point
for t = 1:numel(x)
r = x(t);
nnn = y(t);
set(p1, 'xdata',[get(p1,'xdata') r], ...
'ydata',[get(p1,'ydata') nnn])
set(p2, 'xdata',r, 'ydata',nnn)
pause(.5)
% In the first iteration the origin is added to [p1]!!!
end
I cannot guess, what you want to do instead. Perhaps you want to start your t-loop from 2 or remove the zeros from x and y.
  2 个评论
Jan
Jan 2011-4-28
Puh, the latency is cruel for me. I've typed the answer and waited 13 minutes until it appears completely in the web interface. Therefore I did not see Paulo's answer before.
Chris Berry
Chris Berry 2011-4-28
Ha. I still appreciate you trying to help me. Take care.
~ Chris

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by