Two line simple animation

Hello,
I have the following two lines plot. I want to animate both plots at the same time. I want to start from time 0 to time 9. I have tried the following code. For some reason
I don't understand it only plots the first plot only. How can also I save the animation to power point?
Thanks
GH
clear all
clc
h=animatedline;
axis([0,10,0,10]);
time=[0 1 2 3 4 5 6 7 8 9];
y1=[0 3 5 7 9 3 4 5 5 5];
y2=[0 1 3 4 5 1 3 4 4 4];
for k=1:length(time)
addpoints(h,time(k),y1(k));
drawnow
hold on
addpoints(h,time(k),y2(k));
drawnow
hold on
end

回答 (2 件)

Chad Greene
Chad Greene 2017 年 7 月 26 日

0 投票

It seems you want two animated line objects.
h1=animatedline;
h2=animatedline;
axis([0,10,0,10]);
time=[0 1 2 3 4 5 6 7 8 9];
y1=[0 3 5 7 9 3 4 5 5 5];
y2=[0 1 3 4 5 1 3 4 4 4];
for k=1:length(time)
addpoints(h1,time(k),y1(k));
drawnow
hold on
addpoints(h2,time(k),y2(k));
drawnow
hold on
end
As for making the animation for powerpoint, you'll have to decide what video format to use. For a gif you can use my gif function.
Star Strider
Star Strider 2017 年 7 月 26 日

0 投票

You need to define animatedline for each line.
See if this does what you want:
h1=animatedline;
h2=animatedline;
axis([0,10,0,10]);
time=[0 1 2 3 4 5 6 7 8 9];
y1=[0 3 5 7 9 3 4 5 5 5];
y2=[0 1 3 4 5 1 3 4 4 4];
for k=1:length(time)
addpoints(h1,time(k),y1(k));
hold on
addpoints(h2,time(k),y2(k));
drawnow
end
hold off

2 件のコメント

friet
friet 2017 年 7 月 28 日
Thanks for the answer. How can I change the color of the plots. I try
addpoints(h1,time(k),y1(k),'r');
However it didnt work. Any help will be appriciated.
Thanks
Star Strider
Star Strider 2017 年 7 月 28 日
My pleasure.
You need to specify the color (and other options, if desired) in the animatedline call:
h1=animatedline('Color','r');
That will create a red line for ‘h1’.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

タグ

質問済み:

2017 年 7 月 26 日

コメント済み:

2017 年 7 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by