Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Problem With a Simple For Loop
Date: Sun, 18 Oct 2009 22:50:22 -0400
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <hbgk46$7a7$1@fred.mathworks.com>
References: <hbfofq$9mi$1@fred.mathworks.com> <hbfpqs$4bp$1@fred.mathworks.com> <hbfrmt$mi$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1255920582 7495 172.31.44.65 (19 Oct 2009 02:49:42 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 19 Oct 2009 02:49:42 +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:578261



"Ali Moradi" <kimusubi@gmail.com> wrote in message 
news:hbfrmt$mi$1@fred.mathworks.com...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message 
> <hbfpqs$4bp$1@fred.mathworks.com>...
>> "Ali Moradi" <kimusubi@gmail.com> wrote in message 
>> <hbfofq$9mi$1@fred.mathworks.com>...

*snip*

> I see what you mean, and I think I fixed it. I just added another loop and 
> made it look like this:
>
> for j = 1:8
>    for i = 2:9
>        dzu(j) = PPZU(i)-PPZU(i-1);
>        dzl(j) = PPZL(i)-PPZL(i-1);
>        dx(j) = PPX(i)-PPX(i-1);
>    end
> end
>
> Does that look about right? Thanks again.

There's no need for a double loop here.  Either use the loop from 2 to 9 and 
remove the first element after the loop is finished:

dzu(1) = [];

or find some way to 'map' 2:9 to 1:8 and use that 'map' to convert the loop 
variable into the appropriate index value.  If you understand the following 
example, you should be able to adapt it to your needs:

z = zeros(1, 10);
for k = 2:2:20
    z(k/2) = k;
end
% Of course, if that was really your goal, you would just use z = 2:2:20;

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ