Error using meshgrid function.

29 views (last 30 days)
VIJENDRA
VIJENDRA on 9 Oct 2014
Commented: VIJENDRA on 10 Oct 2014
I have 2 matrices 'A' and 'B' both of size 500*500. when i am trying to create meshgrid using
[X1,Y1] = meshgrid(A,B);
this shwo error "Out of memory. Type HELP MEMORY for your options. Error in meshgrid (line 58) xx = xrow(ones(size(ycol)),:);"
Can anyone tell why is it happening? Is there any size limit for the variable?
  2 Comments
Andrew Reibold
Andrew Reibold on 9 Oct 2014
I get the same thing with 500x500, but it works ok for 100x100
The bottom line, is that to do that exactly as written you will need a bigger toaster.
Star Strider
Star Strider on 9 Oct 2014
You may not need to use meshgrid.
What are you calculating or plotting?

Sign in to comment.

Accepted Answer

Andrew Reibold
Andrew Reibold on 9 Oct 2014
Edited: Andrew Reibold on 9 Oct 2014
The reason is this.
Lets say I make two 500x500 matrices using the following.
A = ones(500,500);
B = 4*ones(500,500);
Lets look at how big one of those is
whos A
Name Size Bytes Class Attributes
A 500x500 2000000 double
2,000,000 Bytes is 2 Megabytes.
Now to run meshgrid, the grid vector A is replicated numel(B) times to form the columns of X
How many times is that?
numel(B)
ans =
250000
2BM * 250,000 is the same as 500GB
Do you have 500GB available?
You can check using memory. Here is an example
memory
Maximum possible array: 89643 MB (9.400e+10 bytes) *
Memory available for all arrays: 89643 MB (9.400e+10 bytes) *
Memory used by MATLAB: 3493 MB (3.663e+09 bytes)
Physical Memory (RAM): 16308 MB (1.710e+10 bytes)
Here I can see that I only have enough space for about 90GB of array space when for this process I will need 500GB. This means I result in the same error as you.
meshgrid(A,B)
Error using repmat
Out of memory. Type HELP MEMORY for your options.
Error in meshgrid (line 58)
xx = repmat(xrow,size(ycol));
And that is why you are having your problem! Not enough memory available on your computer. You will need to try to split the problem up or perhaps lower grid resolution if possible.
I hope this explanation answered your question, good luck!
  1 Comment
VIJENDRA
VIJENDRA on 10 Oct 2014
Thank you Andrew Reibold, its very good description.

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!