|
"John Baillie" wrote in message <jvql00$3k2$1@newscl01ah.mathworks.com>...
> Hello,
>
> I am copying large amounts of data to a structure array:
> data_voltage<1x3> structure
> Each of the nine cells contains a structure with two fields, x and y, for example:
> data_voltage(1,1).x
> data_voltage(1,3).y
> Each field will contain a matrix of 5e6 rows and 1 column, for example:
> data_voltage(1,1).x(5e6,1)=3.9467
>
> Since I am copying my data from fields in a for loop it is necesary that I preallocate the cells to avoid memory issues. I have done this as follows:
> data_voltage=struct('x',{zeros(5e6,1), zeros(5e6,1), zeros(5e6,1),}, 'y',{zeros(5e6,1), zeros(5e6,1), zeros(5e6,1)});
>
> Is there a way to improve this code so that i do not need to repeat the line zeros(5e6,1) 3 times? I have tried using the cell command but to no avail.
>
> Thanks,
> John
data_voltage=struct('x',repmat({zeros(5e6,1)},1,3), 'y',repmat({zeros(5e6,1)},1,3);
Barry
|