Path: news.mathworks.com!not-for-mail
From: "Anh Huy Phan" <phananhhuy@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help: Finding 2nd max value index
Date: Thu, 10 Jan 2008 12:24:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 42
Message-ID: <fm52p2$lid$1@fred.mathworks.com>
References: <16223830.1199960323818.JavaMail.jakarta@nitrogen.mathforum.org>
Reply-To: "Anh Huy Phan" <phananhhuy@mathworks.com>
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 1199967842 22093 172.30.248.37 (10 Jan 2008 12:24:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 10 Jan 2008 12:24:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 113206
Xref: news.mathworks.com comp.soft-sys.matlab:445188


Dan <dan_ang_25@yahoo.com> wrote in message 
<16223830.1199960323818.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hi guys, 
> 
> I am pretty new here.
> 
>  This code helps me to find the max value index. [C,index] = 
max(sim_output16,[],2);
> 
> I like to ask, how do i find the next max value index.
> What code should i type. is there any ?


Remove the largest elements in your data or set them to the 
minimum value in each row.
Then find maximum value again.

Or you can use unique function
   a = [3 5 7 6 7]
   ua = unique(a)
        3 5 6 7
   max2nd = ua(end-1)


However, if you want to find the second maximum in each row of 
one matrix, the code looks like this:

  a = randint(3,10,[1 8])     % data
  n = 2; % order
  mnd = blkproc(a,[1 size(a,2)],@(x) maxnd(x,n))


where the function maxnd is as following

     function y = maxnd(x,n)
          y = unique(x);
          y = y(end-n+1);

HTH

Anh Huy Phan
RIKEN - BSI