Dynamic Plotting "Phantom" Line
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 28 Apr. 2011
Please use the code formatting as described at the link called "Markup" on this page.
Akzeptierte Antwort
Paulo Silva
am 28 Apr. 2011
Initialize p1 with this code
p1=plot(nan,nan,'r-');
instead of
p1=plot(r,nnn,'r-');
Weitere Antworten (1)
Jan
am 28 Apr. 2011
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 Kommentare
Jan
am 28 Apr. 2011
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.
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!