Home > Archive > Matlab > March 2007 > vectorized preallocation of structure
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
vectorized preallocation of structure
|
|
|
| Hi,
I have a function that creates movies of surface plots. A movie
matrix is grown by adding plot frames with some rotation about the
z-axis.
There are 361 frames of truecolor data, each are 400x600x3.
The resultant movie structure m consists of 1x361 struct array with
fields cdata and colormap.
As described, the cdata for each frame is 400x600x3. The colormap
does not vary between frames and is 1024x3 (rgb).
I would like to preallocate this structure. I would like to
preallocate the cdata with zeros and would like to preassign the
colormap information with my extant static colormap C.
An attempt to loop through preallocation fails for lack of memory:
for j = 1:361
m(j).cdata = zeros(400,600,3);
m(j).colormap = C;
end
I've been trying to vectorize this preallocation with snippets like
this without success (psuedo-code):
[m(1,1:361).cdata] = zeros(400,600,3);
Any hint or help would be much appreciated.
Scott
| |
|
| Scott wrote:
>
>
> Hi,
>
> I have a function that creates movies of surface plots. A movie
> matrix is grown by adding plot frames with some rotation about the
> z-axis.
>
> There are 361 frames of truecolor data, each are 400x600x3.
>
> The resultant movie structure m consists of 1x361 struct array with
> fields cdata and colormap.
>
> As described, the cdata for each frame is 400x600x3. The colormap
> does not vary between frames and is 1024x3 (rgb).
>
> I would like to preallocate this structure. I would like to
> preallocate the cdata with zeros and would like to preassign the
> colormap information with my extant static colormap C.
>
> An attempt to loop through preallocation fails for lack of memory:
>
> for j = 1:361
> m(j).cdata = zeros(400,600,3);
> m(j).colormap = C;
> end
>
> I've been trying to vectorize this preallocation with snippets like
> this without success (psuedo-code):
>
> [m(1,1:361).cdata] = zeros(400,600,3);
>
> Any hint or help would be much appreciated.
>
> Scott
Solved. Correct code:
m(361).cdata = zeros(400,600,3);
C = colormap;
m(361).colormap = C;
Scott
|
|
|
|
|