フィルターのクリア

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 Center および File ExchangeGraphics Objects についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by