Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help: Finding 2nd max value index
Date: Thu, 10 Jan 2008 17:58:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 30
Message-ID: <fm5mba$glr$1@fred.mathworks.com>
References: <fm5dvd$5u9$1@fred.mathworks.com> <24132754.1199981108620.JavaMail.jakarta@nitrogen.mathforum.org>
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 1199987882 17083 172.30.248.37 (10 Jan 2008 17:58:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 10 Jan 2008 17:58:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 113206
Xref: news.mathworks.com comp.soft-sys.matlab:445237




Dan, you replace the maxnd function by the new one

function y = maxnd(x,n)
[xu,ind] = unique(x);
y = [xu(end-n+1) ind(end-n+1)]; 


One example shows how to use this function

a = [4     5     3     4     7
     8     3     2     1     6
     7     3     4     5     3];
n = 2;
mnd = blkproc(a,[1 size(a,2)],@(x) maxnd(x,n))


mnd =

     5     2
     6     5
     5     4


The first column is the 2nd max values along the rows, and 
the 2nd column is the column indices of the correspondent 
elements.

Anh Huy Phan
RIKEN - BSI