Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: combine data?
Date: Wed, 16 Jul 2008 09:21:38 -0400
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <g5ksl2$ij3$1@fred.mathworks.com>
References: <g5k9qk$kc5$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1216214498 19043 144.212.105.187 (16 Jul 2008 13:21:38 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 16 Jul 2008 13:21:38 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Xref: news.mathworks.com comp.soft-sys.matlab:479739




"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