Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sums and loops
Date: Fri, 4 Jan 2008 14:09:55 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 66
Message-ID: <fllenj$9i8$1@fred.mathworks.com>
References: <flkv6k$fa$1@fred.mathworks.com> <fll0jh$7rt$1@fred.mathworks.com> <flldtq$1bh$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 1199455795 9800 172.30.248.37 (4 Jan 2008 14:09:55 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Jan 2008 14:09:55 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 113206
Xref: news.mathworks.com comp.soft-sys.matlab:444327



To Dave:

You have vector p = [1:9]
and you need to generate vector s
   s(1) = p(1) + p(2) + p(3)
   s(2) = p(4) + p(5) + p(6)
   ...

but you don't want to use 'reshape' function???

Anh Huy Phan
RIKEN - BSI

"Dave " <bocconiluck@yahoo.com> wrote in message 
<flldtq$1bh$1@fred.mathworks.com>...
> 
> 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
> > 
>