- #1
Nick89
- 555
- 0
Hi,
This isn't really technically a homework question but I thought I'd still ask here...
I am solving a spring pendulum model (set of differential equations) using Matlab, and the homework assignment tells me to plot the trajectory of the bob in the x-y plane. Well, I did that, but I find it is fairly hard to see anything in the plot. I mean, it's a nice curvy line and all, but I can't really verify if it 'looks natural' or not.
So, I wanted to make it into a movie, using the following code:
Here, X and Y are the x and y coordinates of the solution (motion of the bob).
Now, I can see the bob move up and down nicely while swinging left to right. It also draws the spring or suspension rope between the point (0,0) and (X,Y) each frame.
The problem however is that I don't want my script to actually PLOT each individual frame, because I am already plotting the x(t) vs time, y(t) vs time, and x(t) vs y(t) plots (as the assignment asks me to do). Now, these plots are lost because they're overwritten by the movie plots.
Can I not plot the plots 'into memory' and store them in the F frames array that way? Then, I can return the frames array F and let the user play the movie manually using the movie() command.
Is that possible?
This isn't really technically a homework question but I thought I'd still ask here...
I am solving a spring pendulum model (set of differential equations) using Matlab, and the homework assignment tells me to plot the trajectory of the bob in the x-y plane. Well, I did that, but I find it is fairly hard to see anything in the plot. I mean, it's a nice curvy line and all, but I can't really verify if it 'looks natural' or not.
So, I wanted to make it into a movie, using the following code:
Code:
% movie
for i = 1:length(X)
plot(X(i),Y(i),'o'); axis([-10 10 -10 10]);
line([0,X(i)],[0,Y(i)]);
F(i) = getframe;
end
movie(F, 1, 25);
Now, I can see the bob move up and down nicely while swinging left to right. It also draws the spring or suspension rope between the point (0,0) and (X,Y) each frame.
The problem however is that I don't want my script to actually PLOT each individual frame, because I am already plotting the x(t) vs time, y(t) vs time, and x(t) vs y(t) plots (as the assignment asks me to do). Now, these plots are lost because they're overwritten by the movie plots.
Can I not plot the plots 'into memory' and store them in the F frames array that way? Then, I can return the frames array F and let the user play the movie manually using the movie() command.
Is that possible?
Last edited: