Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Create a new vector from a current vector
Date: Mon, 5 Nov 2007 16:25:41 +0000 (UTC)
Organization: fz
Lines: 22
Message-ID: <fgng65$d9h$1@fred.mathworks.com>
References: <fgnbec$21u$1@fred.mathworks.com> <fgnes3$mop$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 1194279941 13617 172.30.248.37 (5 Nov 2007 16:25:41 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 5 Nov 2007 16:25:41 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1088664
Xref: news.mathworks.com comp.soft-sys.matlab:436122



"us " <us@neurol.unizh.ch> wrote in message
<fgnes3$mop$1@fred.mathworks.com>...
> Amir Safari:
> <SNIP wants to sum subvecs of a larger one
> 
> others have shown you the typical way to do it...
> one of the more versatile solutions is outlined below
> 
> % the data
>      a=[1,3,3,4,2,4,3,5,5,2,4,3,7,4,2,4,1,4,2,3];
> % - define the starting indices of your subvecs
>      abeg=[1,6,7,10,18];
> % the engine
>      aend=[abeg(2:end)-1,numel(a)];
>      r=arrayfun(@(b,e) sum(a(b:e)),abeg,aend);
> % the result
>      [abeg;aend] % the subvecs
>      r
> 
> us

sorry i don“t get the same results