Plot a normal figure and animatedline together onthe same figure
16 views (last 30 days)
Show older comments
Hi everyone,
I have a question about how to plot a regular figure (using plot or plot3) and animated lines (using animatedline and addpoints) in the same figure.
I want also to record a video of the entire figure. Can I do that with regular way of getfram and VideoWriter?
Here is an example
t=0:0.01:10;
x=cos(t);
y=sin(t);
z=t;
h=animatedline('Color','r');
k=animatedline('Color','b');
view(3)
for i=1:length(t)
addpoints(h,x(i),y(i),z(i));
addpoints(h,0.5*x(i),0.5*y(i),z(i));
% I want also to plot the following in the same figure
plot3(x,y,z) % I want the graph to apear in full in the begining not as an animated line
end
Can anyone help me with that?
Thank you
0 Comments
Accepted Answer
dpb
on 7 Jan 2021
Edited: dpb
on 8 Jan 2021
...
% I want also to plot the following in the same figure
% I want the graph to apear in full in the begining not as an animated line
% then plot it first, if that is what is desired
plot3(x,y,z)
view(3)
% then must set hold on to add to an axes or will clear existing stuff
hold on
h=animatedline('Color','r');
for i=1:length(t)
addpoints(h,x(i),y(i),z(i));
addpoints(h,0.5*x(i),0.5*y(i),z(i));
pause(0.01)
end
This fills the area between the outer and inner lines; not clear to me why it appears to be solid surface. If only add the inner points alone, then get the two lines, but the outer one isn't traced as one presumes is the intended effect.
ADDENDUM:
The solid comes from using the same animated line handle for both...since the two calls alternate inner/outer positions, the lines are drawn back and forth between the two. They're close enough together to give the illusion of a surface which is, at first, confusing as to what one is seeing.
Not sure what the intended look really is, but
h=animatedline('Color','r');
k=animatedline('Color','r');
for i=1:length(t)
addpoints(h,x(i),y(i),z(i));
addpoints(k,0.5*x(i),0.5*y(i),z(i));
pause(0.01)
end
gives the two lines, one retracing original curve and the inner at half diameter.
5 Comments
More Answers (0)
See Also
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!