From: "Steven_Lord" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: out of memory error
Date: Thu, 26 Apr 2012 09:47:26 -0400
Organization: MathWorks
Lines: 54
Message-ID: <jnbjle$khr$>
References: <jna18u$6al$>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
X-Trace: 1335448046 21051 (26 Apr 2012 13:47:26 GMT)
NNTP-Posting-Date: Thu, 26 Apr 2012 13:47:26 +0000 (UTC)
In-Reply-To: <jna18u$6al$>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: comp.soft-sys.matlab:766003

"Sanaa " <> wrote in message 
> Hi,
> I always get the error: out of memory even if i try to reduce the size of 
> my parameters!
> clear
> itermax=100;
> finalits=30;finits=itermax-(finalits-1);
> for ru=0:0.005:2;
> for a=0.01:0.005:1;
>    x=zeros(1,itermax);
>    x0=0.2;x1= 0.25;
>    x(1)=x0;x(2)=x1;
>    for i=2:itermax
>        x(i+1)= -a*x(i)+ ru*x(i-1)*(1-x(i-1));
>    end
> plot3(a*ones(finalits),ru*ones(finalits),x(finits:itermax),'.','MarkerSize',1)

You're plotting almost 80,000 lines due to the double nested FOR loops over 
ru and a. Your monitor doesn't have enough pixels to show all the points on 
all those lines, but each line requires two 71-by-71 matrices and a 
71-element vector. Now 71-by-71 matrices may sound small, and they generally 
are, but a large number of small matrices still chew up memory pretty 
quickly. There's an old saying that captures what you're experiencing: 
"death by a thousand paper cuts."

You can reduce the amount of memory you're using a _little_ by calling ONES 
with two inputs to create a _vector_ rather than a _matrix_:

a*ones(1, finalits)

or by calling REPMAT:

repmat(a, 1, finalits)

But a bigger win would be to find a way to avoid creating tens of thousands 
of lines.


> title('ru= 3.5')

This doesn't look correct, given the limits on your first FOR loop.

Steve Lord
To contact Technical Support use the Contact Us link on