MATLAB Answers

Create an animated free body diagram?

32 views (last 30 days)
Brandon Holladay
Brandon Holladay on 27 Oct 2020
Answered: Srivardhan Gadila on 30 Oct 2020
Is it possible to animate a free body diagram with a force changing over time? I already calculated an array with all the force values, but have no way of animating it in a good way besides plotting it like any other graph.

  3 Comments

Image Analyst
Image Analyst on 27 Oct 2020
Yes, but what's wrong with doing a line plot with plot()? What are you looking for?
Brandon Holladay
Brandon Holladay on 27 Oct 2020
I specifically want to show the change of force as an animation rather than a static plot. I have tried the "for" control to plot frames of the graph, but that updates the figure to a completely new plot with a new ylim and xlim.
Sindar
Sindar on 27 Oct 2020
set the xlim before the loop

Sign in to comment.

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 30 Oct 2020
You can refer to the documentation of plot, pause, Specify Axis Limits, hold & figure.
The following is the example code based on the above functions:
1. If you want the point moving i.e., new point to appear and previous point to disappear:
figure
for i = 1:10
plot(i,abs(sqrt(100-i^2)),'o');
xlim([0 10])
ylim([0 10])
% hold on
pause(1)
end
% hold off
2. If you want all the previous points to appear in the plot as well:
figure
for i = 1:10
plot(i,abs(sqrt(100-i^2)),'o');
xlim([0 10])
ylim([0 10])
hold on
pause(1)
end
hold off

  0 Comments

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!