Path: news.mathworks.com!not-for-mail
From: "jay vaughan" <jvaughan5.nospam@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: combine data?
Date: Wed, 16 Jul 2008 16:57:04 +0000 (UTC)
Organization: harvard
Lines: 42
Message-ID: <g5l990$2ci$1@fred.mathworks.com>
References: <g5k9qk$kc5$1@fred.mathworks.com> <g5ksl2$ij3$1@fred.mathworks.com>
Reply-To: "jay vaughan" <jvaughan5.nospam@gmail.com>
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 1216227424 2450 172.30.248.37 (16 Jul 2008 16:57:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 16 Jul 2008 16:57:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1215048
Xref: news.mathworks.com comp.soft-sys.matlab:479779



"Steven Lord" <slord@mathworks.com> wrote in message <g5ksl2
$ij3$1@fred.mathworks.com>...
> 
> "jay vaughan" <jvaughan5.nospam@gmail.com> wrote in 
message 
> news:g5k9qk$kc5$1@fred.mathworks.com...
> > Hi,
> >
> > I am trying to find a way to combine data without using 
a
> > loop. My data are similar to the following.
> >
> > width  = [1 4 4 5 6 10 10 10 16];
> > weight = [1 1 2 1 1 4  2  2  1];
> >
> > I would like to find a way to combine all entries where 
the
> > width was the same, finding the total weight, like 
below.
> >
> > combined_width  = [1 4 5 6 10 16];
> > combined_weight = [1 3 1 1 8  1];
> >
> > I have to do this a million times or so and was hoping 
to
> > do it efficiently. Any ideas on how to vectorize 
something
> > like this?
> 
> Use ACCUMARRAY.  If your widths are not integers, UNIQUE 
them and use the 
> unique indices to construct the subs input.
> 
> -- 
> Steve Lord
> slord@mathworks.com 
> 
> 

Thanks Peter and Steve, accumarray works great!
J