how to crate a video of multiple surf plots ?
6 views (last 30 days)
Show older comments
I am running a code which produces a surf plot for every step of the loop. I want to create a video of the all these surf plots produced in each step. How can I do that?
Accepted Answer
KSSV
on 30 Oct 2018
h = figure;
axis tight manual % this ensures that getframe() returns a consistent size
filename = 'test.gif';
[X,Y,Z] = peaks(100) ;
for n = 1:50
% Draw plot for y = x.^n
surf(X,Y,randsample(10,1)*Z) ;
zlim([-100 100])
shading interp
drawnow
% Capture the plot as an image
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the GIF File
if n == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
end
3 Comments
Walter Roberson
on 30 Oct 2018
If you do use imwrite() to write GIF specifically, then you can add
'DelayTime', 5
to the imwrite() calls, to cause the frame to be displayed for 5(ish) seconds.
If you create a movie using the techniques I linked to, then the general strategy would be to write the same frame multiple times -- either that or when you called VideoWriter() you pass in 'FrameRate', 1/5 so as to set it up for 1 frame every 5 seconds.
More Answers (0)
See Also
Categories
Find more on Read, Write, and Modify Image 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!