Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: memory usage with plot function
Date: Tue, 20 Jan 2009 09:22:26 -0500
Organization: The MathWorks, Inc.
Lines: 70
Message-ID: <gl4mn2$2jm$1@fred.mathworks.com>
References: <gl4ffm$9u3$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1232461346 2678 144.212.105.187 (20 Jan 2009 14:22:26 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 20 Jan 2009 14:22:26 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:512705



"Theodor Zouk" <rebet4@hotmail.com> wrote in message 
news:gl4ffm$9u3$1@fred.mathworks.com...
> Hi
> I have three questions:
> 1) Is there a way to see how much memory it takes to plot variables in 
> matlab?

No.

> For example i have the variables:
>
> y = rand(1,40000000);
> x= 0:1/(40000000-1):1;
> plot(x,y)
>
> these takes 2 x 320 000 000 = 640 MB (double class) to store in the 
> memory. When I try to plot them i run out of memory.

Yes.  The object created by the PLOT function stores the X and Y data used 
to create it as the XData and YData properties inside the object.  That 
means that when you PLOT, you need four contiguous blocks of 320 MB each --  
two for the x and y variables, and two for the XData and YData properties. 
If you don't have two more contiguous blocks of memory, MATLAB will 
correctly throw an Out of Memory error.

Now obviously this is a contrived example.  Two approaches you could use 
with your real data would be to resample your data (using INTERP1 or 
RESAMPLE) or to plot your data in pieces and only keep around those regions 
of interest.

> 2) Why doesn't matlab allways "return" memory back to operating system 
> after using the plot function.

See above.

> I.e sometimes i try to plot large variables but runs out of memory, When I 
> then CLEAR ALL, Matlab still uses all lot of the memory according to 
> Windows Task Manager, and according to FEATURE MEMSTATS my Largest Cont. 
> Free Block is only half the size of the biggest block when im first 
> initializing Matlab. I have used the CLEAR and PACK function but i can not 
> get a bigger Larg.Cont. Free Bloc. The only solution is to restart Matlab 
> and thats a realy poor solution according to me... :-/

If you have the PLOT open, then the best you could do would be to clear the 
variables from the workspace.

> 3) Is there a way to organize the 'Largest Contiguous Free Blocks', I mean 
> concatenate/defragmentate/release them somehow, without using PACK 
> function( cause it can not run in a script nor a function)

No.

> Im doing the calculation on a Windows XP SP2 32-bit, 3GB RAM.

You should read these documents on the support website:

http://www.mathworks.com/support/tech-notes/1100/1106.html

http://www.mathworks.com/support/tech-notes/1100/1107.html

If you're not using the 3GB switch, that may help you somewhat; but if 
you're going to be performing lots of calculations on large data sets, you 
probably want to use a 64-bit OS and a 64-bit version of MATLAB.

-- 
Steve Lord
slord@mathworks.com