Out of memory. Type HELP MEMORY for your options.
Show older comments
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 Comments
Jan
on 16 May 2013
You forgot to mention in which line this error occurres.
sita
on 16 May 2013
sita
on 17 May 2013
Jan
on 17 May 2013
I do not understand the problem. What is the goal of the arrayfun?
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.
sita
on 17 May 2013
Accepted Answer
More Answers (1)
"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.
Categories
Find more on Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!