Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Give me a good example for accumarray()
Date: Sat, 4 Jul 2009 15:26:01 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 6
Message-ID: <h2nsa8$gdd$1@fred.mathworks.com>
References: <h2n5b9$lo7$1@fred.mathworks.com> <h2n8tm$46f$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246721161 16813 172.30.248.38 (4 Jul 2009 15:26:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 4 Jul 2009 15:26:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:552782


Here's an odd one.  

Say you wanted to find the row number in which each unique value in a matrix of positive integers appears, then store these row numbers in a cell array.  (Don't ask.)

M = ceil(rand(20,3)*10); % Data.
C = accumarray(M(:), repmat((1:size(M,1))', [size(M,2) 1]), [], @(x) {x});