separate animated simultaneous line plots

9 views (last 30 days)
edward
edward on 27 Aug 2011
Commented: Walter Roberson on 7 Mar 2017
i am trying to plot 2 separate line plots simultaneously (see code below); the problem i am having is when i put the following line "set(hb,'XData',x,'YData',yb)" in the for loop just after the 1st set command "set(h,'XData',x,'YData',y)" it doesn't like it...I can separate into 2 separate for loops and it runs but I want the two data sets to run simultaneously...I've tried nesting the 2nd for loop and it runs 1 and then the other...i've searched on the web and on help for a solution but am stuck...i am a relative novice w/ metlab and have much to learn below is the two for loops in their full...any help would be appreciated!
xs=data(:,1);
x=xs(1,1);
ys=data(:,2);
%ysb=data(:,4);%bonn sub added
y=ys(1,1);%initiates 1st value
%yb=ysb(1,1); %bonn sub add initial start point
h=plot(x,y);
%hb=plot(x,yb);
grid on
set(h,'EraseMode','xor');
set(h,'linewidth',3.5,'color','red');
%bonn part
% set(hb,'EraseMode','xor');
% set(hb,'linewidth',4.5,'color','green');
Xlabel('time (24 hrs)')
Ylabel('Megawatts')
legend('blue: mean of two previous days','red: jeff dispatch','green: bonn dispatch')
axis([1,1440,10,60]);
for k=1:1440
x(k)=xs(k,1)
y(k)=ys(k,1)
set(h,'XData',x,'YData',y)
drawnow
%pause()%set pause to0.02
end
hold on
%_______________________________________________________________________
%bonne plot section
xs=data(:,1);
x=xs(1,1);
ysb=data(:,4);%bonn sub added
yb=ysb(1,1); %bonn sub add initial start point
hb=plot(x,yb);
get(gca)
grid on
%bonn part
set(hb,'EraseMode','xor');
set(hb,'linewidth',3.5,'color','green');
Xlabel('time (24 hrs)')
Ylabel('Megawatts')
legend('blue: mean of two previous days','red: jeff dispatch','green: bonn dispatch')
axis([1,1440,10,60]);
for k=1:1440
x(k)=xs(k,1)
yb(k)=ysb(k,1)%bonne section
set(hb,'XData',x,'YData',yb)%bonn portion of the plot
drawnow
%pause()set pause to0.02
end
get(hb)

Answers (1)

Walter Roberson
Walter Roberson on 28 Aug 2011
"It didn't like it" is not sufficient to know what you are seeing.
Is there any particular reason why you do not simply code this all as:
hs = plot(data(:,1),data(:,2), 'r', data(:,1), data(:,4), 'g');
set(hs, 'linewidth', 3.5, 'EraseMode', 'xor');
plus whatever titles you want?
  2 Comments
Paul C
Paul C on 6 Mar 2017
For instance I would like to plot a normal graph, and a polar one next to it, so you can't combine both in a single graph.
Walter Roberson
Walter Roberson on 7 Mar 2017
With current MATLAB, R2014b and later, you can use <https://www.mathworks.com/help/matlab/ref/animatedline.html animatedline() . You would create your two axes and pass the appropriate axes handle to the animatedline() call when you created the line.
With R2016a or later, you would prefer to use polaraxes for the polar plot. For earlier versions you would use polar() but the coordinates you would have to add to the animated line would probably have to be cartesian coordinates rather than polar coordinates.
Note: the DrawMode xor discussed in this Question from 2011 no longer exists as of R2014b.

Sign in to comment.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!