Animating plot in a for loop

4 ビュー (過去 30 日間)
Ege Arsan
Ege Arsan 2021 年 1 月 16 日
編集済み: Cris LaPierre 2021 年 1 月 16 日
I have the following figure and i want to animate it with addpoints but couldn't work it out.
dy is the displacement from an ode solver, which is a matrix of 549x4 doubles and n = 2, so i only plot the dy(:,3) and dy(:,4)
  2 件のコメント
Image Analyst
Image Analyst 2021 年 1 月 16 日
I don't know. MATLAB cannot convert your image into code. Attach your code so we can run it. What is "addpoints" - is that a built-in or custom function? Attach dy in a .mat file. Make it easy to help you not hard.
Ege Arsan
Ege Arsan 2021 年 1 月 16 日
Sorry. Here are the codes. You can run the code Vibration_Plot.m and enter the forces as '0' (they should be in quotes). The MDK.m is only for generating the matrices.

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

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 1 月 16 日
Use the animatedline function. Follow this example from the documentation.
  6 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 1 月 16 日
編集済み: Cris LaPierre 2021 年 1 月 16 日
It's easier to debug one thing at a time. Once you have the ode working, then focus on the animation. It's usually a good idea to only include in the for loop code that needs to be run multiple times. The title, labels, and grid commands can be set once, so move those before the loop.
It is my suspicion you will have to create an animated line for each subplot.
Here is a simplified working example that you can modify to your needs.
L=animatedline;
axis([ti,tf,-4,4])
title(['Response q',num2str(i)]);
xlabel('Time, seconds'); ylabel('Displacement, m');
grid on;
for i = 1:length(dy)
addpoints(L,t(i),dy(i,1));
drawnow
end
Ege Arsan
Ege Arsan 2021 年 1 月 16 日
Thank you so much! I will work on this.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by