Out of memory. Type HELP MEMORY for your options.
8 次查看(过去 30 天)
显示 更早的评论
Hi, Please find below code.It gives Out of memory. HELP MEMORY for your options.Error in ndgrid (line 66) x = reshape(x(:,ones(1,prod(s))),[length(x) s]); . Please help me resolving this.
Thanks, Sita
clc; clear; tic p = haltonset(1) %'Skip',1e3,'Leap',1e2);
i1=1; j1=10;
i2=1; j2=10;
i3=1; j3=10;
i4=1; j4=10;
i5=1; j5=10;
i6=1; j6=10;
i7=1; j7=10;
i8=1; j8=10;
i9=1; j9=10;
i10=1; j10=10;
x1s(:,:)=p(i1:j1,:); x2s(:,:)=p(i2:j2,:); x3s(:,:)=p(i3:j3,:); x4s(:,:)=p(i4:j4,:); x5s(:,:)=p(i5:j5,:); x6s(:,:)=p(i6:j6,:); x7s(:,:)=p(i7:j7,:); x8s(:,:)=p(i8:j8,:); x9s(:,:)=p(i9:j9,:); x10s(:,:)=p(i10:j10,:);
[aa bb cc dd ee ff gg hh ii jj]=ndgrid(x1s,x2s,x3s,x4s,x5s,x6s,x7s,x8s,x9s,x10s);
overnested = arrayfun(@(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10],aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,'un',0);
celldisp(overnested)
x = permute([aa(:), bb(:),cc(:),dd(:),ee(:),ff(:),gg(:), hh(:),ii(:),jj(:)],[ 11 10 9 8 7 6 5 4 3 2 1]);%replaced below code
x1temp=x(1,1,1,1,1,1,1,1,1,1,:)
x2temp=x(1,1,1,1,1,1,1,1,1,2,:)
x3temp=x(1,1,1,1,1,1,1,1,1,3,:)
x4temp=x(1,1,1,1,1,1,1,1,1,4,:)
x5temp=x(1,1,1,1,1,1,1,1,1,5,:)
x6temp=x(1,1,1,1,1,1,1,1,1,6,:)
x7temp=x(1,1,1,1,1,1,1,1,1,7,:)
x8temp=x(1,1,1,1,1,1,1,1,1,8,:)
x9temp=x(1,1,1,1,1,1,1,1,1,9,:)
x10temp=x(1,1,1,1,1,1,1,1,1,10,:)
6 个评论
José-Luis
2013-5-17
编辑:José-Luis
2013-5-17
The usefulness of using a 10 dimensional ndgrid has to be questioned. Storing a double requires 64 bits or 8 bytes of memory. To give you an idea, assuming all dimensions are of equal length (all you x's have the same size), here are the storage requirements for 10-dimensional arrays:
- size 2: 2^10 * 8 = 8192 bytes -> 8kB
- size 5: 78125000 bytes -> 78MB
- size 10: 8e10 bytes -> 80GB (out of range for a desktop nowadays)
- size 20: 8.19e13 bytes -> 81TB (way out of theoretical range for 64bit computers)
I strongly suggest you revise your approach. Creating an ndgrid might not only be unnecessary, it is also probably a bad idea.
采纳的回答
José-Luis
2013-5-17
编辑:José-Luis
2013-5-17
All possible permutations in a loop:
for ii = 1:numel(x1)
for jj = 1:numel(x2)
for kk = 1:numel(x3)
your_input = [x1(ii) x2(jj) x3(kk)]
end
end
end
This could help with your out of memory error. Depending on the sizes of the vector it might take a long time. Please accept an answer if it helps you.
4 个评论
José-Luis
2013-5-21
You are trying to perform 10^10 operations. Depending on the complexity of your function, that is bound to take some time. As a quick test:
tic;for ii=1:10^10;end;toc
Time elapsed = 19 seconds. Just going through the loop counter takes a while. I would image that even the simplest of function could take a very long time.
There might be a trade-off between speed and memory consumption. That being said, you have several alternatives to make your code faster. The first step is to use the profiler to find bottlenecks in your code and optimize the functions that are taking the most time. After doing that, you have several alternatives
- Parallelize your code (doc parfor, parallel computing toolbox and others)
- Get a faster computer
- Use a lower level language, such as C/C++ or Fortran that are bound to be much faster than Matlab.
更多回答(1 个)
Jan
2013-5-16
编辑:Jan
2015-8-3
"Out of memory" means, that you try to create an array, which does not fit into the available free memory.
The solutions are trivial:
- Install more memory (twice as much is a good strategy)
- Because RAM is cheap even more memory is fine
- Switch off other applications, which occupy memory
- Clear unused variables in Matlab
- Use smaller data types if possible (a double needs 8 bytes, a uint16 only 2)
- Use a 64-bit system and Matlab, such that you can use the bunch of gigabytes you have installed according to the points 1. and 2.
You find exactly the same answers, when you search in the forum for "Out of memory".
[EDITED]
Another problem might be, that you try to create a 10 dimensional ndgrid. I'm not sure why you use matrices as input to ndgrid, because I'd expect vectors -- but this might be meaningful for reasons I do no know. But 10 dimensional regular grids tends to be extremely huge. If each dimension has 10 elements, Matlab needs to store 10^10 elements. So I guess, that there is a design problem and you want to do something else.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!