A moving line plot between two points in MATLAB figure

7 ビュー (過去 30 日間)
Rajawarman Thiruselvam
Rajawarman Thiruselvam 2021 年 7 月 5 日
コメント済み: Amit Bhowmick 2021 年 7 月 6 日
Hi everyone, I need help to do an animated line for known coordinates
For example: (x1,y1),(x2,y2),(x3,y3) are known variables
here i want the point should be moving slowly from x1,y1 to x3,y3 via x2,y2
How can i do this??

採用された回答

Amit Bhowmick
Amit Bhowmick 2021 年 7 月 5 日
For large number of iteration use loop accordingly.
clearvars
close all
clc
x1=0.1;y1=0.2;
x2=0.3;y2=0.4;
x3=0.5;y3=0.6;
hold on
frm=[];
axis([0 1 0 1])
plot(x1,y1,'o')
frm=[frm getframe()];
plot([x1 x2],[y1 y2])
frm=[frm getframe()];
plot(x2,y2,'o')
frm=[frm getframe()];
plot([x2 x3],[y2 y3])
frm=[frm getframe()];
plot(x3,y3,'o')
frm=[frm getframe()];
movie(frm,3,1)
  2 件のコメント
Rajawarman Thiruselvam
Rajawarman Thiruselvam 2021 年 7 月 5 日
can you please give me an another example using loops??
Amit Bhowmick
Amit Bhowmick 2021 年 7 月 5 日
clearvars
close all
clc
hold on
frm=[];
axis([-2 12 -2 120])
x=0:0.5:10;
y=x.^2;
for ii=1:length(x)
plot(x(ii),y(ii),'o')
frm=[frm getframe()];
end
movie(frm,1,12)

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

その他の回答 (1 件)

Rajawarman Thiruselvam
Rajawarman Thiruselvam 2021 年 7 月 6 日
frm=[];
frm=[frm getframe()];
can you please explain this??
  1 件のコメント
Amit Bhowmick
Amit Bhowmick 2021 年 7 月 6 日
frm=[] creats an emty varriable with size 0x0.
getframe() capture the current plot and store the frame adding one more extra column to frm with [frm getframe()].
check this following thing to understand this operation:
a=[1 2 3 4];
a=[a 3]

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

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by