Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find indices when using accumarray
Date: Mon, 3 Mar 2008 21:25:14 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 71
Message-ID: <fqhqbq$e65$1@fred.mathworks.com>
References: <fc3lv6$ovb$1@fred.mathworks.com> <fqh7tj$oea$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 1204579514 14533 172.30.248.37 (3 Mar 2008 21:25:14 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 3 Mar 2008 21:25:14 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870595
Xref: news.mathworks.com comp.soft-sys.matlab:455112



Hi Ilya,

I am deeply impressed. Thanks a lot, this worked out.

Best regards,
Wolfgang
 

"Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu> wrote in
message <fqh7tj$oea$1@fred.mathworks.com>...
> 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
> > 
>