I have a 3D array of values (0 or 1), which is very large (approx 2300x2300x11). I want to fit a surface to these values using for example interp3, but when I try MATLAB runs out of memory. Thus, I’ve decided to reduce the size of my array enough for MATLAB to accomodate it in memory.
Now, the smaller I make the reduced array, the worse my results will be (the surface fitting is part of a measurement process with high precision requirements), so I want to reduce the array as little as possible.
Is there any way to determine on beforehand how much memory a certain array size will demand and how much memory is available, and then use this information to resize the array enough to avoid out of memory exceptions, but not more?
You can look at the maximum array sizes that are supported on different platforms. In general, if you have a
PxQxRsized 3D array ofdoubles, then the size of your array in bytes isP*Q*R*8. For your matrix, the size is ~ 444 MB. You can also try reducing it to asingle, usingsingle(A).singleuses 4 bytes per element and you can reduce the size of your array by a factor 2.I haven’t really poked into the inner workings of
interp3, but the exact memory requirements will depend on the interpolation option you choose. So, you can first try to convert it tosingleand see if it works. If not, try with 80% (90%) of the number of rows and columns. This way you have a good chunk of the original array, but the memory requirement is only 64% (81%) of the original.If that doesn’t help, duffymo’s suggestion is what you should be looking into.