|
In article <g4uoq1$20v$1@fred.mathworks.com>,
Mark <nospamthank@yahoo.com> wrote:
>I know most of the memory error issues (contiguous blocks
>etc) but can't quite understand why it is I'm getting an out
>of memory error on a particular line. I do the right thing
>and pre-allocate the memory block using...
>
>mth_ret = zeros(nsims, mths, ac, 'single');
>
>but get the out of memory error in the subsequent loop that
>performs variable assignment...
>
>for j = 1:ac
> mth_ret(:,:,j) = <variable>.<field>.<var>(1:nsims,:);
>end
When you take a sub-section of a vector and it isn't immediately
obvious to Matlab that you are copying vectors of the same size
around, then Matlab may have to take a temporary copy of the source data
as part of the assignment process. The taking of that temporary
copy may fill up memory.
I -believe- Matlab is smart enough to get away without temporary
copies in some straight-forward cases, but my -expectation- is that
those cases would be only when entire columns are copied. I speculate
that it is possible that if you were to reverse the first and second
dimensions of the source and destination that Matlab might perhaps
be able to get away without creating a temporary copy.
--
"I like to build things, I like to do things. I am having
a lot of fun." -- Walter Chrysler
|