Path: news.mathworks.com!not-for-mail
From: "Ali " <alihaider82@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Attempted to access ; index out of bounds
Date: Sun, 19 Apr 2009 22:12:01 +0000 (UTC)
Organization: University of Belgrade
Lines: 46
Message-ID: <gsg7jh$j69$1@fred.mathworks.com>
References: <gsfsh6$4m3$1@fred.mathworks.com> <gsftbd$q3i$1@fred.mathworks.com>
Reply-To: "Ali " <alihaider82@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1240179121 19657 172.30.248.38 (19 Apr 2009 22:12:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 19 Apr 2009 22:12:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440530
Xref: news.mathworks.com comp.soft-sys.matlab:533936


"Jiro Doke" <jiro.doke@mathworks.com> wrote in message <gsftbd$q3i$1@fred.mathworks.com>...
> "Ali " <alihaider82@gmail.com> wrote in message <gsfsh6$4m3$1@fred.mathworks.com>...
> > i have written this code listed below:
> > 
> > far(1) = 0.001;
> > for i=2:10000000
> >     far(i+1) = (h(1400,0,far(i)) - h(684,0,0))/(0.999*43100 - h(1400,0,far(i)));
> >  
> >     if abs(far(i) - far(i+1)) <= 0.001
> >          
> >         break       
> >        far(i)
> >     else
> >         return
> >     end
> > end
> > 
> > it gives erroe: ??? Attempted to access far(2); index out of bounds because
> > numel(far)=1.
> > 
> > Error in ==> far_iter at 4
> >     far(i+1) = (h(1400,0,far(i)) - h(684,0,0))/(0.999*43100 -
> >     h(1400,0,far(i)));
> > 
> > sometimes it works without changing anything,sometimes it gives error. Plz help me.
> > Ali
> >    
> 
> Ali,
> 
> If you step through the code line by line, you'll notice that an error happens the first time through the loop. "i" starts from 2, so the first line reads:
> 
> far(3) = (h(1400,0,far(2)) - h(684,0,0))/(0.999*43100 - h(1400,0,far(2)));
> 
> Well, there is no far(2) yet, because you only have defined far(1).
> 
> It works sometimes, because you are probably not clearing the memory between runs.
> 
> jiro

Thanks Jiro. I have chenged now;
for i = 1:10000000

but now it didn't work. no result. What should I do now?

Ali