COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### how to solve *out of memory* error

• Follow

```Hi guys,
I just started to use matlab. I got the *out of memory* error while I used the following commands:
[X,Y]=meshgrid(out(:,1),out(:,2));
Z=griddata(out(:,1),out(:,2),out(:,3),X,Y);
surf(X,Y,Z);
the out.txt is smaller than 300kb. And I am pretty sure that the memory available is big enough. Although I am not so sure how to check it. It would be great if someone could help me to find it out and solve this problem.
Thanks a lot.

wei
```
 0

```How many elements are in the 'out' variable?  If it is N-by-3, then you should be aware that X,Y,Z are all N-by-N.  If N is very large, it is easy to see why you get such an error.  You may need to filter, for example:

out = out(1:2:end,:)
[X,Y] = ....

since you surf plot may not need such fine detail if N is very large.
```
 0

```Hi Matt,
There are indeed N-by-3 elements in the out. I guess you have pointed out why would I have this problem. But I tried the filter you mentioned like below:
out = out(1:2:end,:);
[X,Y]=meshgrid(out(:,1),out(:,2));

it still gave me the *out of memory* error. Could you help me to figure it out, please?
Thank you very much.

wei
```
 0

```Wei wrote:

>    I just started to use matlab. I got the *out of memory* error while I
> used the following commands:
> [X,Y]=meshgrid(out(:,1),out(:,2));
> Z=griddata(out(:,1),out(:,2),out(:,3),X,Y);
> surf(X,Y,Z);

You do not need to create the grid for the purposes of griddata or surf:

z = griddata(out(:,1),out(:,2),out(:,3),out(:,1),out(:,2));
surf(out(:,1),out(:,2),Z);
```
 0

```Hi Walter,
Thanks a lot for your attention.
But I think  if we want to use mesh or surf, we need to create our meshgrid, as
iin regular 2D plot when we want to plot sth against sth, right?
Anyway, I tried your way. I just got an empty plot...
```
 0

```Wei wrote:

> Thanks a lot for your attention.
> But I think  if we want to use mesh or surf, we need to create our
> meshgrid, as
> iin regular 2D plot when we want to plot sth against sth, right?

Newer versions of Matlab detect that a vector was given for x and y and
treat it as if you had done a meshgrid() but without you having to
actually create the matrix.

> Anyway, I tried your way. I just got an empty plot...

Which Matlab version are you using?
```
 0

```Version 7.0.1.24704 (R14) Service Pack 1.
I guess it's too old...
```
 0

```Wei wrote:
> Version 7.0.1.24704 (R14) Service Pack 1.
> I guess it's too old...

Yes, I suspect R14 is too old to support giving vectors instead of
meshes for surf() and griddata.

You could work in sections, such as half of the x vs half of the y for
the grid, and either put the four sections together into a single matrix
for surf() or else do multiple surf() calls -- as long as you get the
correct x and y coordinates and use "hold on" then in theory the
surfaces should end up positioned next to each other. It _might_ help.
But how big are your arrays? And I don't think I caught whether the
memory error was in doing the meshgrid() or in doing the griddata ? You
think you have enough memory, but it would be good to have someone else
take a look at the figures. Use "who" to tell how big a variable is. If
you are on a PC, try memstats() to see the amount of free memory you
have available... it may well be significantly less than you thought.
```
 0

```Walter Roberson <roberson@hushmail.com> wrote in message <bEIKn.37385\$304.14325@newsfe12.iad>...
> Wei wrote:
> > Version 7.0.1.24704 (R14) Service Pack 1.
> > I guess it's too old...
>
>
> Yes, I suspect R14 is too old to support giving vectors instead of
> meshes for surf() and griddata.
>
> You could work in sections, such as half of the x vs half of the y for
> the grid, and either put the four sections together into a single matrix
> for surf() or else do multiple surf() calls -- as long as you get the
> correct x and y coordinates and use "hold on" then in theory the
> surfaces should end up positioned next to each other. It _might_ help.
> But how big are your arrays? And I don't think I caught whether the
> memory error was in doing the meshgrid() or in doing the griddata ? You
> think you have enough memory, but it would be good to have someone else
> take a look at the figures. Use "who" to tell how big a variable is. If
> you are on a PC, try memstats() to see the amount of free memory you
> have available... it may well be significantly less than you thought.

The array is 3 by 128*128.
And the error was in doing the meshgrid.
Below is what I got for the memory:
Physical Memory (RAM):
In Use:                              918 MB (39677000)
Free:                               1111 MB (457c2000)
Total:                              2030 MB (7ee39000)
Page File (Swap space):
In Use:                              728 MB (2d8eb000)
Free:                               3193 MB (c79b9000)
Total:                              3922 MB (f52a4000)
In Use:                              323 MB (14323000)
Free:                               1724 MB (6bcbd000)
Total:                              2047 MB (7ffe0000)
Largest Contiguous Free Blocks:
1. [at 25075000]                    447 MB (1bf8b000)
2. [at 41044000]                    413 MB (19d2c000)
3. [at 11810000]                    311 MB (137f0000)
4. [at 69d76000]                    125 MB (07d2a000)
5. [at 629c9000]                    107 MB (06b37000)
6. [at 5d12a000]                     88 MB (05896000)
7. [at 73026000]                     29 MB (01d6a000)
8. [at 5b8b5000]                     23 MB (017db000)
9. [at 71c03000]                     19 MB (013fd000)
10. [at 7e4a1000]                     18 MB (0124f000)
======= ==========
1585 MB (6312f000)

Thanks a lot.
```
 0

```Wei wrote:

>    Largest Contiguous Free Blocks:
>         1. [at 25075000]                    447 MB (1bf8b000)

That is your maximum array size. I calculate that is about a 3 x 4420 x
4420 array, so I not immediately sure why your arrays do not fit. I
suggest you put in

whos
memstats

right before your meshgrid() call, to see how much memory you have
available at that point; also print out the size of "out" so you can
calculate how big an array is being requested.
```
 0

9 Replies
722 Views

Similiar Articles:

7/22/2012 9:01:45 AM