Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Problem With a Simple For Loop
Date: Sun, 18 Oct 2009 19:53:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 41
Message-ID: <hbfrmt$mi$1@fred.mathworks.com>
References: <hbfofq$9mi$1@fred.mathworks.com> <hbfpqs$4bp$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1255895581 722 172.30.248.38 (18 Oct 2009 19:53:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 18 Oct 2009 19:53:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1592646
Xref: news.mathworks.com comp.soft-sys.matlab:578210


"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>...
> > Hi,
> > 
> > I'm writing a simple for loop for a homework problem and I'm coming across a weird problem that I can't figure out. I have 3 vectors all of size 9x1. I'm doing the following for loop:
> > 
> > for i = 2:9
> >     dzu(i) = PPZU(i)-PPZU(i-1);
> >     dzl(i) = PPZL(i)-PPZL(i-1);
> >     dx(i) = PPX(i)-PPX(i-1);
> > end
> > 
> > The problem is that when I run it, I get a 9x1 vector as the answer, but it should be a 8x1 vector instead. 
> 
> No, length 9 is correct.
> 
> > Does anyone have any idea as to why this is happening? 
> 
> A simply setting
> 
> d(1000)=1
> 
> will give 1x1000 vector
> 
> Bruno



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.

- Ali