Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sums and loops
Date: Fri, 4 Jan 2008 13:56:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <flldtq$1bh$1@fred.mathworks.com>
References: <flkv6k$fa$1@fred.mathworks.com> <fll0jh$7rt$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 1199454970 1393 172.30.248.38 (4 Jan 2008 13:56:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Jan 2008 13:56:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 875558
Xref: news.mathworks.com comp.soft-sys.matlab:444323




thanks for the reply, i explain the question further 

p=[1 2 3 4 5 6 7 8 9]'

we need a code that sums elements in p for ex the first
three elements at a time resulting in a new column s

s=[6 15 24]'

(6=1+2+3 .. 15=4+5+6 ... 24= 7+8+9 ...)

I tried reshape in didnt work but thanks for the input




"Huy " <phananhhuy@mathworks.com> wrote in message
<fll0jh$7rt$1@fred.mathworks.com>...
> 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
>