Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!n7g2000prc.googlegroups.com!not-for-mail
From: Siyi <Mr.Siyi.Deng@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Creating a new vector based on unique entries
Date: Thu, 14 May 2009 13:10:16 -0700 (PDT)
Organization: http://groups.google.com
Lines: 35
Message-ID: <1edcb1d3-04a7-4c56-bd32-dde07e68c7a8@n7g2000prc.googlegroups.com>
References: <guh7ap$s7n$1@fred.mathworks.com> <guhrld$m89$1@fred.mathworks.com> 
	<guht49$r8b$1@fred.mathworks.com>
NNTP-Posting-Host: 128.195.202.150
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1242331817 19604 127.0.0.1 (14 May 2009 20:10:17 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 14 May 2009 20:10:17 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: n7g2000prc.googlegroups.com; posting-host=128.195.202.150; 
	posting-account=2xaS4woAAABMTlLr8rCm508E1dml7wGx
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) 
	Gecko/2009042513 Ubuntu/8.04 (hardy) Firefox/3.0.10,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:540035


On May 14, 12:58 pm, "us " <u...@neurol.unizh.ch> wrote:
> "us"
> the broken TMW newsreader starts to get on my nerves...
>
> one of the many solutions (hope it works this time...)
> - copy/paste
>
> % the data
> % - note: your data combined in one cell for sake of brevity...
>      d={
>           'cat'          1
>           'cat'          2
>           'dog'          4
>           'cat'          3
>           'dog'          8
>           'mouse'      -10
>      };
> % the engine
>      n = cat(1,d{:,2});     % <- your 2nd data set...
>      [du,ix,ix] = unique(d(:,1));
>      r = accumarray(ix,n,[],@mean);
> % the result
>      disp([du,num2cell(r)]);
> %{
>     'cat'      [  2]
>     'dog'      [  6]
>     'mouse'    [-10]
> %}
>
> us

us, I realized that accumarray(...,@mean) can be slower than using


r = accumarray(ix,n)./accumarray(ix,1);