A moving line plot in MATLAB figure with animation between 3 points
13 ビュー (過去 30 日間)
古いコメントを表示
Rajawarman Thiruselvam
2021 年 7 月 5 日
回答済み: Johannes Hougaard
2021 年 7 月 6 日
Hi everyone, I need help to do an animated line for known coordinates
for example :(x1,y1)=(2,1)
(x2,y2)=(3,2)
(x3,y3)=(4,2)
simply i can plot these lines , but don't know how to animate from one point to another point. How can i do this??
3 件のコメント
採用された回答
Johannes Hougaard
2021 年 7 月 6 日
Could be something like this then...
It's super inefficient code and can definitely be improved in speed as well as complexity.
x = [2 3 4];
y = [1 2 2];
totaltime = seconds(10);
steptime = totaltime/length(x);
figure;
for ii = 1:length(x)-1
npoints = 999;
pointsx = linspace(x(ii),x(ii+1),npoints);
pointsy = linspace(y(ii),y(ii+1),npoints);
for jj = 1:npoints
pause(seconds(steptime)/npoints);
plot([x(1:ii),pointsx(jj)],[y(1:ii),pointsy(jj)],'-o');
xlim([min(x)*.8 max(x)*1.2]);
ylim([min(y)*.8 max(y)*1.2]);
end
end
0 件のコメント
その他の回答 (1 件)
Srijan Jain
2021 年 7 月 5 日
Hey,
I understand you're trying to animate a line between 2 points.
I would suggest you to look into: Update figures and process callbacks - MATLAB drawnow
Hope this helps
Srijan
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Animation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!