0

I would like to preallocate the following structure before a for-loop. It is used to save M=getframe(i).

enter image description here

I tried the following:

M=struct(cdata, zeros(1,559), colormap);

Which logically comes up with:

Undefined function or variable 'cdata'.

Question Is there a way to pre-allocate the structure for a movie directly ? Or do I have to assign 343x434x3 uint 8 to cdata ? (And if yes how would I do that?).

EDIT I guess this is not a duplicate of the following thread, as this is specially about the pre-allocation of a movie struct. How to initialize an array of structs in MATLAB?

@ Luis Mendo

I tried pre-allocating your way:

comes up with the following problem:

Conversion to uint8 from struct is not possible.

Error in UG9 (line 238)
M(i)=getframe;

I would be glad for any help, maybe I just dont understand the method of pre-allocating as described in the above thread.

Community
  • 1
  • 1
KiW
  • 593
  • 3
  • 20
  • 3
    Since you have no colormap and all `cdata` are the same size, why not just use a 4D array? `M = zeros(343,343,8,559, 'uint8');` and then fill it with `M(:,:,:,counter) = ...` – Luis Mendo Jun 20 '16 at 09:41
  • If you were to read the documentation for struct you'd see that the first input needs to be a string, because it's the name of a field... – sco1 Jun 20 '16 at 10:21
  • 1
    And it is the same, there is no such thing as a "movie struct" in MATLAB. A structure is a structure. – sco1 Jun 20 '16 at 10:22
  • Where is the 1,559 coming from? I don't see that in your table. – siliconwafer Jun 20 '16 at 19:27
  • thats dependant on the loop as a frame is saved everytime the loop creates a new "picture" for the movie – KiW Jun 21 '16 at 10:38

0 Answers0