Pre-calculating memory usage of repmat.m to avoid out of memory errors
3 次查看(过去 30 天)
显示 更早的评论
A and B are equal length vectors of my data. The max value in A is 100 and the max value in B is 20,000 and n = 2,500. I wish to run the following code
n = length(A); % length(A) == length(B);
a = 1; b =1;
gridx1 = [1 : a : max(ceil(A))];
gridx2 = [1 : b : max(ceil(B))];
[gridx2,gridx1] = meshgrid(gridx2,gridx1);
x1 = repmat(gridx1, [1,1,n]);
x2 = repmat(gridx2, [1,1,n]);
mu1 = repmat(A,[length(gridx1),length(gridx2),1]);
mu2 = repmat(B,[length(gridx1),length(gridx2),1]);
However I get an out of memory error. Hence I need to reduce the sampling frequency of the grids.
Lets say I wish to allocate up to 3GB of RAM to this process, how can I find the sampling frequency, "a" and "b".
Obviously I wish to sample at the maximum frequency possible (subject to the 3GB constraint) to get the most accurate answer.
thank you
2 个评论
Jan
2013-2-7
Isn't this a simple division? Do 3GB belong to one oy the arrays e.g. mu2, or is it the sum of all defined arrays?
Jason Ross
2013-2-7
编辑:Jason Ross
2013-2-7
I'll state what I hope is pretty obvious: If you are regularly hitting "Out of memory" issues, you really should move to a 64-bit operating system. The hardware and operating systems have supported it for years now. Barring a few specialized use cases (generally related to hardware drivers), there is no downside to moving to a 64-bit operating system. RAM is also quite inexpensive, 16 GB can be had for less than $100, 24 GB less than $150, 32 GB less than $200 and even 64 GB is running ~$350. This, of course, assumes a desktop host with a motherboard that can take these types of chips.
采纳的回答
更多回答(1 个)
cr
2013-2-7
编辑:cr
2013-2-7
say, Lg1 is length(gridx1) and Lg2 is length(gridx2). Then your variables need this much memory x1: Lg1*Lg2*n*8 bytes (assuming you are using doubles), x2: Lg1*Lg2*n*8 bytes This is where the problem lies. Other not so big. Use singles or integer types if doubles are not necessary. Or, do your operations sequentially clearing intermediate variables.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!