Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: find indices when using accumarray
Date: Mon, 10 Sep 2007 14:56:38 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <fc3lv6$ovb$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1189436198 25579 172.30.248.37 (10 Sep 2007 14:56:38 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 10 Sep 2007 14:56:38 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870595
Xref: news.mathworks.com comp.soft-sys.matlab:427704



Dear community,

I got a problem using accumarray

ind = [1 2 3 1 2 3 1 2 3]';
val = [0.1:0.1:0.9]';
A = accumarray(ind,val,[3 1],@max)
A =

    0.7000
    0.8000
    0.9000

Now I don't want the maximum value but the index in val,
where the maximum is found. So I wrote my own function...
_________________________
function ix = findmax(s);
[m,ix] = max(s);
_________________________

... and entered:

A = accumarray(ind,val,[3 1],@findmax)

A =

     1
     2
     2

I don't know what A is telling me now but obviously it is
not what I wanted. I want A to be

A = [7 8 9]';

Is there a way to do so (without using sparse matrices?)

Best regards and thanks,
Wolfgang