Getting error: "Movie cdata must be of type uint8 array" despite the fact that my movie cdata *is* of type uint8 array.

1 Ansicht (letzte 30 Tage)
Hi! I'm trying to play a movie from an array of frames that I recorded using surf. Here is the code that is generating an error:
zlim manual;
frames(numel(T)) = struct('cdata',[],'colormap',[]);
for frame_num = 1:numel(T)
surf(reshape(KE(frame_num, 2:m-1, 2:n-1), m-2, n-2));
hold on
surf(reshape(NE(frame_num, 2:m-1, 2:n-1), m-2, n-2));
hold off
zlim([0 140]);
frames(frame_num) = getframe();
end
for frame_num = 1:numel(T)
frames(frame_num).cdata = uint8(frames(frame_num).cdata);
end
movie(frames, 5)
and here is the error:
Error using hgMovie
Movie cdata must be of type uint8 array
Error in movie (line 41)
builtin('hgMovie',varargin{:});
Error in astro2d_main (line 110)
movie(frames, 5)
I'm quite confused because a) I'm explicitly casting the cdata to uint8 and b) MATLAB reports that the data is in fact in the correct format anyway:
frames(1)
ans =
cdata: [343x435x3 uint8]
colormap: []
Any help solving this would be wonderful! Thanks.
ps: let me add that the individual frames are rendering just fine and calling
image(frames(1).cdata)
does exactly what I expect it to.

Akzeptierte Antwort

Steven Lord
Steven Lord am 31 Jul. 2015
Double-check that ALL the data is uint8.
isUint8 = arrayfun(@(x) isequal(class(x.cdata), 'uint8'), frames) % Not tested but should work
If any of the elements of isUint8 are false, check the corresponding frames. My suspicion is that you previously had data in frames and that the T you're using this time has fewer elements than the T you used the first time you created frames. That "leftover" data may be interfering. If the last several elements of isUint8 are false, this would support that guess.
  2 Kommentare
Richard Buckalew
Richard Buckalew am 31 Jul. 2015
Thanks Steven, that appears to be exactly it. Moral of the story: add a clear at the top of a complex script.
Sean de Wolski
Sean de Wolski am 31 Jul. 2015
Better moral of the story would be to write this as a function so it has its own workspace!
That way you don't clear out old things, and don't run into these errors.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 31 Jul. 2015
Minimal working example, does this work:
f = getframe
movie([f f],5)
If it doesn't then you're probably shadowing a command somewhere that movie is using
  3 Kommentare
Sean de Wolski
Sean de Wolski am 31 Jul. 2015
Bearbeitet: Sean de Wolski am 31 Jul. 2015
Strange. Is it possible that frames was initially larger than numel(T) and so there were non-uint8 CData values after the ones you filled in in the loop. I would speculate it's either that or that one frame somewhere was empty.
Richard Buckalew
Richard Buckalew am 31 Jul. 2015
You and Steven both found it. This is too easy a problem for this forum, but thanks for your prompt and helpful answers!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by