Path: news.mathworks.com!not-for-mail
From: "Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find indices when using accumarray
Date: Mon, 3 Mar 2008 16:10:27 +0000 (UTC)
Organization: Citizens Bank
Lines: 60
Message-ID: <fqh7tj$oea$1@fred.mathworks.com>
References: <fc3lv6$ovb$1@fred.mathworks.com>
Reply-To: "Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu>
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 1204560627 25034 172.30.248.37 (3 Mar 2008 16:10:27 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 3 Mar 2008 16:10:27 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1195850
Xref: news.mathworks.com comp.soft-sys.matlab:455060



I saw your question on the Loren's blog but I decided to 
answer here since it seems to be a more proper forum.  
Anyway, how about something like this


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

where

function ix = findmax(indx, s)
[m,ix] = max(s(indx));
ix =  indx(ix);




"Wolfgang Schwanghart" <schwanghart@googlemail.com> wrote 
in message <fc3lv6$ovb$1@fred.mathworks.com>...
> 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
>