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:27:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 82
Message-ID: <fllfnq$rh5$1@fred.mathworks.com>
References: <flkv6k$fa$1@fred.mathworks.com> <fll0jh$7rt$1@fred.mathworks.com> <flldtq$1bh$1@fred.mathworks.com> <fllenj$9i8$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1199456826 28197 172.30.248.35 (4 Jan 2008 14:27:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Jan 2008 14:27:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 875558
Xref: news.mathworks.com comp.soft-sys.matlab:444334



I have millions of observations in P, i tried reshape but it
didnt work, the example i provided was just to illustrate
the question on small vectors. 

Reshape is producing an error . i am looking for non
overlapping subsums over fixed interval as in the example i
provided.

Thanks a lot for your reponse



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