Path: news.mathworks.com!not-for-mail
From: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Problem With a Simple For Loop
Date: Mon, 19 Oct 2009 08:30:05 +0000 (UTC)
Organization: Ricardo UK Ltd
Lines: 14
Message-ID: <hbh82d$s7o$1@fred.mathworks.com>
References: <hbfofq$9mi$1@fred.mathworks.com>
Reply-To: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.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 1255941005 28920 172.30.248.38 (19 Oct 2009 08:30:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 19 Oct 2009 08:30:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 43398
Xref: news.mathworks.com comp.soft-sys.matlab:578304


"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. Does anyone have any idea as to why this is happening? Thank you all in advance for your help.

Why loop at all?  diff() will do your homework for you.