Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sums and loops
Date: Fri, 4 Jan 2008 10:08:49 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <fll0jh$7rt$1@fred.mathworks.com>
References: <flkv6k$fa$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1199441329 8061 172.30.248.37 (4 Jan 2008 10:08:49 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Jan 2008 10:08:49 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 113206
Xref: news.mathworks.com comp.soft-sys.matlab:444305



p = sum(reshape(z,[5 20]))'

Anh Huy Phan
RIKEN - BSI


"D Jurdi" <bocconiluck@yahoo.com> wrote in message 
<flkv6k$fa$1@fred.mathworks.com>...
> I am stuck writing a loop, any help??
> 
> The problem:
> z is a vector of 100 numbers
> i would be generating a col vector p which sums the first 5
> elements of z then the second 5 elements and so on (non
> overlapping) , z will have 20 elements. 
> 
> I tried this but :(
> 
> for z=1:20
>     for i=1:100;
>         j=(i+2):100;
>         p(z)=sum(sp(i:j));
>         end
>     end
> 
> end 
> 
> thanks for any help