Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: HOWTO: Accelerate processing algorithm
Date: Sun, 5 Jul 2009 16:28:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 21
Message-ID: <h2qkah$nkk$1@fred.mathworks.com>
References: <14646834.75779.1246802812202.JavaMail.jakarta@nitrogen.mathforum.org> <1e37765c-af3c-49d8-8465-8203f0c78f19@d4g2000yqa.googlegroups.com> <h2qith$ojj$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246811281 24212 172.30.248.35 (5 Jul 2009 16:28:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 5 Jul 2009 16:28:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:552901


Here is a code to show what ACCUMARRAY does:

% Generate test data
m = 10;
nd = 3;
sidx=ceil(4*rand(m,3)); % must be integers
v=rand(m,1);

% ACCUMARRAY DOES THIS
sz = max(sidx,[],1);
res = zeros(sz);
for k=1:m
    sk = sidx(k,:);
    sk = num2cell(sk);
    res(sk{:}) = res(sk{:}) + v(k,1);
end

% Check
isequal(accumarray(sidx, v), res) % OK 1

% Bruno