Error using movie command in Matlab

2 visualizzazioni (ultimi 30 giorni)
Adrian
Adrian il 8 Mag 2014
Commentato: Adrian il 9 Mag 2014
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!

Risposta accettata

Geoff Hayes
Geoff Hayes il 8 Mag 2014
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 Commento
Adrian
Adrian il 9 Mag 2014
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Animation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by