Creating movie from Images from a for loop
Show older comments
Hi there, I am currently producing images from a for loop, however I would like put these images into a movie or slideshow,however I am struggling to do this. Any help would be appreciated.
if true
% code
end
for i=t:Images
figure(i)
B=readimx(fullfile(filename,['B000',int2str(i),'.im7']));
C=B.Frames{1}.Components{1};
V = C.Planes;
I2=V{1,1};
Array3D(:,:,i-t+1)=I2;
K=imagesc(flipud(Array3D(:,:,i-t+1)));
set(gca,'YDir','normal');
end
Accepted Answer
More Answers (2)
Joseph Cheng
on 29 May 2015
Edited: Joseph Cheng
on 29 May 2015
you can follow the example of getframe() in the documentation located here:
example:
x=1:256;
[x y] = meshgrid(x,x);
figure(1)
vidfile = VideoWriter('testmovie.mp4','MPEG-4');
open(vidfile);
for ind = 1:256
z=sin(x*2*pi/ind)+cos(y*2*pi/ind);
imagesc(z),colormap(hot)
drawnow
F(ind) = getframe(gcf);
writeVideo(vidfile,F(ind));
end
close(vidfile)
Eswaramoorthy
on 3 Dec 2025
MATLAB's VideoWriter can be used to create a video file from images.
Here's an example from the VideoWriter documentation VideoWriter - Create object to write video files - MATLAB, which creates a video from images using a for-loop:
% Set up the axes and figure properties to generate frames for the video.
Z = peaks;
surf(Z);
axis tight manual;
set(gca,"NextPlot","replacechildren");
% Create a VideoWriter object for the output video file and open the object for writing.
v = VideoWriter("peaks.avi");
open(v);
% Generate a set of frames, get each frame from the figure, and then write each frame to the file.
for k = 1:20
surf(sin(2*pi*k/20)*Z,Z);
frame = getframe(gcf);
writeVideo(v,frame);
end
close(v);
Categories
Find more on Convert Image Type 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!