Why is my getframe/movie not displaying my final frame?

1 view (last 30 days)
Hi all,
I'm trying to to make a movie of a robot arm moving through space. Here is my code.
% Plotting
% Make a set of axes
frame0_x = [0 0 0; 10 0 0];
frame0_y = [0 0 0; 0 10 0];
frame0_z = [0 0 0; 0 0 10];
hfig = figure; hold on; grid on; view(27, 35);
xlabel('x'); ylabel('y'); zlabel('z');
xlim([-15 15]); ylim([-15 15]); zlim([-15 15]);
set(gca,'NextPlot','replaceChildren');
% Animate the movie
for j = 1:size(points1_trans, 3)
%pause
cla
hold on
plot3(frame0_x, frame0_y, frame0_z, '--k', 'linewidth', 2);
plot3(link1_x_trans(:, :, j), link1_y_trans(:, :, j), link1_z_trans(:, :, j), 'r', 'linewidth', 1);
plot3(link2_x_trans(:, :, j), link2_y_trans(:, :, j), link2_z_trans(:, :, j), 'r', 'linewidth', 1);
hold off
%pause
F(j) = getframe(hfig);
end
figure
movie(gcf, F, 2, 30)
My problem is that the when the loop cycles through, it displays the motion perfectly. However, when I use movie(), the final frame is the second-to-last position of the robot arm. In other words, it appears that getframe is dropping the final frame in the loop. I verified this by checking with image(F(1, 100).cdata).
What could be causing getframe() to fail to capture the final frame?
Thank you for your time.
  1 Comment
Woo-Jin Cho Kim
Woo-Jin Cho Kim on 14 Jun 2016
Dear Brandon,
Your last frame is probably being projected but its probably because it loops too fast. If you open it as .avi you can pause it at the last second and you would be able to see the last frame.
The problem is that you need to add some sort of wait/pause command before it starts looping the movie again.
Best Regards, WJC

Sign in to comment.

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!