필터 지우기
필터 지우기

Dynamic Plotting "Phantom" Line

조회 수: 5 (최근 30일)
Chris Berry
Chris Berry 2011년 4월 28일
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