"Matt J" wrote in message <k5ipbh$lk$1@newscl01ah.mathworks.com>...
> "Chuck37" wrote in message <k5i7c0$1mr$1@newscl01ah.mathworks.com>...
> > I need a structure that looks like:
> >
> > Later on:
> >
> > for ii = 1:bigNum
> > for jj = 1:smallNum
> > S(ii).x(jj) = someValue;
> > end
> > end
> >
> > Matlab gives me the warning here about S appearing to grow, and the loop takes forever to complete, as though memory is being dealt with inefficiently.
> ========
>
> You can pre-allocate by doing
>
> S(bigNum).x=[];
> S(bigNum).y=[];
>
> However, you should be advised that, even with pre-allocation, structures are a very inefficient way to store data of the kind you describe. Structure elements, unlike numeric arrays, are not stored contiguously in memory, which makes them slow to access and the problem gets worse the larger the structure array. Because all your x and y are the same, it makes more sense (and will be faster) to store them in matrices of dimension bigNum x smallNum.
Thanks, I'll think about how to do that. I, of course, simplified the real situation for the post. Each element actually has 4 vector elements and some metadata that would need to be store separately if I switched away from the structure. So I think what you are suggesting implies sending at least five things to all my support functions instead of one (assuming I still keep metadata in structure form).
> "Chuck37" wrote in message <k5i7c0$1mr$1@newscl01ah.mathworks.com>...
> > I need a structure that looks like:
> >
> > Later on:
> >
> > for ii = 1:bigNum
> > for jj = 1:smallNum
> > S(ii).x(jj) = someValue;
> > end
> > end
> >
> > Matlab gives me the warning here about S appearing to grow, and the loop takes forever to complete, as though memory is being dealt with inefficiently.
> ========
>
> You can pre-allocate by doing
>
> S(bigNum).x=[];
> S(bigNum).y=[];
>
> However, you should be advised that, even with pre-allocation, structures are a very inefficient way to store data of the kind you describe. Structure elements, unlike numeric arrays, are not stored contiguously in memory, which makes them slow to access and the problem gets worse the larger the structure array. Because all your x and y are the same, it makes more sense (and will be faster) to store them in matrices of dimension bigNum x smallNum.
Thanks, I'll think about how to do that. I, of course, simplified the real situation for the post. Each element actually has 4 vector elements and some metadata that would need to be store separately if I switched away from the structure. So I think what you are suggesting implies sending at least five things to all my support functions instead of one (assuming I still keep metadata in structure form).