Trouble with animation (getframe and movie)

1 view (last 30 days)
John
John on 25 Feb 2014
Edited: John on 25 Feb 2014
I'm working on a project and I need to animate a simple line graph. I have a program set up to solve an ode45 and return a matrix. When I graph the 1st column vs. the 3rd column, it graphs perfectly, but I can't figure out how to convert the still image to an animation. Ideally, I'd like to have the existing line remain and have a ball animate along the trajectory. Here's the relevant coding. Any help would be greatly appreciated. Thanks
%%Set up and use ODE45 to evaluate
%
timeint = linspace(0, 20, 200);
initialcond = [x0, xPrime0, y0, yPrime0];
[t x] = ode45('flowanalysis_func' , timeint , initialcond , [] , A , U , V);
%
%%Plot Initial Figure
%
f = figure(1);
plot(x(:,1), x(:,3)); % note this plots perfectly
grid on
xlabel('X (m)')
ylabel('Y (m)')
legend('Sphere')
title('Position of Sphere')
%
%%Animation Loop
%
for j=1:length(x(:,1)) % here's where I'm having trouble. I can't seem to understand the help txt
plot(x(j,:,1),x(j,:,3))
M(j) = getframe;
end
movie(M,10,12)

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!