I'm trying to make a movie with the following code:
x=[-3:0.1:3];
y=[-3:0.1:3];
t=[0:0.1:5];
for i = 1:length(t);
[x,y]=meshgrid(-3:.1:3,-3:.1:3);
z=exp(-(x-t(1,i)).^2-(y-t(1,i)).^2);
surf(x,y,z);
axis('tight')
clear('M');
M(i)=getframe;
end
movie(M);
movie2avi(M,'problem_3.avi');
But it's giving the following error when I run it:
Error using hgMovie
Movie contains uninitialized frames
Please how can I solve this?
Thanks

 채택된 답변

Image Analyst
Image Analyst 2014년 9월 7일

0 개 추천

Why are you deleting the M variable in the loop with the clear() function??? Get rid of that.

댓글 수: 1

Fdee1
Fdee1 2014년 9월 9일
After deleting "clear ('M')" and starting the code with "clear all". It worked! Thanks for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 9월 8일

0 개 추천

Try it this way:
clear all;
clc;
x=[-3:0.1:3];
y=[-3:0.1:3];
t=[0:0.1:5];
hFigure = figure;
numberOfFrames = length(t);
% Set up the movie structure.
% Preallocate recalledMovie, which will be an array of structures.
% First get a cell array with all the frames.
allTheFrames = cell(numberOfFrames,1);
vidHeight = 344;
vidWidth = 446;
allTheFrames(:) = {zeros(vidHeight, vidWidth, 3, 'uint8')};
% Next get a cell array with all the colormaps.
allTheColorMaps = cell(numberOfFrames,1);
allTheColorMaps(:) = {zeros(256, 3)};
% Now combine these to make the array of structures.
myMovie = struct('cdata', allTheFrames, 'colormap', allTheColorMaps);
% Create a VideoWriter object to write the video out to a new, different file.
% writerObj = VideoWriter('problem_3.avi');
% open(writerObj);
% Need to change from the default renderer to zbuffer to get it to work right.
% openGL doesn't work and Painters is way too slow.
set(gcf, 'renderer', 'zbuffer');
[x, y] = meshgrid(-3:.1:3,-3:.1:3);
for frameIndex = 1 : numberOfFrames
z = exp(-(x-t(frameIndex)).^2-(y-t(frameIndex)).^2);
cla reset;
% Enlarge figure to full screen.
% set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
surf(x,y,z);
axis('tight')
zlim([0, 1]);
caption = sprintf('Frame #%d of %d, t = %.1f', frameIndex, numberOfFrames, t(frameIndex));
title(caption, 'FontSize', 15);
drawnow;
thisFrame = getframe(gca);
% Write this frame out to a new video file.
% writeVideo(writerObj, thisFrame);
myMovie(frameIndex) = thisFrame;
end
% close(writerObj);
message = sprintf('Done creating movie\nDo you want to play it?');
button = questdlg(message, 'Continue?', 'Yes', 'No', 'Yes');
drawnow; % Refresh screen to get rid of dialog box remnants.
close(hFigure);
if strcmpi(button, 'No')
return;
end
hFigure = figure;
% Enlarge figure to full screen.
% set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
title('Playing the movie we created', 'FontSize', 15);
% Get rid of extra set of axes that it makes for some reason.
axis off;
% Play the movie.
movie(myMovie);
uiwait(helpdlg('Done with demo!'));
close(hFigure);

카테고리

도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2014년 9월 7일

댓글:

2014년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by