Error using movie command in Matlab

조회 수: 3 (최근 30일)
Adrian
Adrian 2014년 5월 8일
댓글: Adrian 2014년 5월 9일
I generated multiple images which I converted into frames with im2frame in order to create a movie. I used this code:
for i = 10:20
images = sprintf('img%d.jpg',i);
ImageData = imread(images);
M(i) = im2frame(ImageData);
end
movie(M)
movie2avi(M,'sonar.avi','compression','None','fps',5,'quality',100)
When I run it, I get the following error:
Error using hgMovie
Movie contains uninitialized frames
Error in movie (line 41)
builtin('hgMovie',varargin{:});
Error in open83B_edited_2 (line 324)
movie(M)
Does anyone have a clue what might be wrong with my code? Thank you!

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 5월 8일
Hi Adrian,
I was able to reproduce the same issue with your above code. The problem is how the M array is being updated. The for loop iterates from 10 to 20 and the code uses these iteration values to assign the frame to the array. This means that M becomes an array of 20 frames, with the first nine not initialized - hence the error.
You can try the following instead:
% use this index into M
idxInM = 1;
for i = 10:20
images = sprintf('img%d.jpg',i);
ImageData = imread(images);
M(idxInM) = im2frame(ImageData);
idxInM = idxInM + 1;
end
Or any other mechanism that allows you to control how M is updated at each iteration.
  댓글 수: 1
Adrian
Adrian 2014년 5월 9일
Thank you very much for your answer. In the end, I managed to solve it right away. You are right, yes. What I did is just write M(i-9) instead of M(i), and it worked. You can also skip out the index, and just write M, and still it would work.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by