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 14:26:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 46
Message-ID: <fm59tq$9ir$1@fred.mathworks.com>
References: <fm52p2$lid$1@fred.mathworks.com> <16045218.1199972757574.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 1199975162 9819 172.30.248.37 (10 Jan 2008 14:26:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 10 Jan 2008 14:26:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 113206
Xref: news.mathworks.com comp.soft-sys.matlab:445200


Dan <dan_ang_25@yahoo.com> wrote in message 
<16045218.1199972757574.JavaMail.jakarta@nitrogen.mathforum.org>...
> a = randint(3,10,[1 8]) % data
> n = 2; % order
> mnd = blkproc(a,[1 size(a,2)],@(x) maxnd(x,n))
> 
> Sorry, i do not understand this code. how should i 
decipher it. sorry i am very new to matlab. i am still at 
the learning stage. can u explain to me


% generate a random maxtrix a: 3x8 in the range [1 8]
% for more detail :    help randint    
% if you don't have this function, try 
% a = ceil(8*rand(3,10))

a = randint(3,10,[1 8]) 

% specify the maximum degree
n = 2; 


% use blkproc function in IMAGE PROCESSING TOOLBOX 
% for block processing
% for more detail :  help blkproc

mnd = blkproc(a,[1 size(a,2)],@(x) maxnd(x,n))

% if you don't have this function, try this code
%
% mnd = zeros(size(a,1),1);
% for r = 1: size(a,1)
%     ua = unique(a(r,:));
%     mnd(r) = ua(end-n+1);
% end


You can copy and run the above code in the command window. 
And you also need to create the function file 'maxnd.m' if 
using blkproc funtion.

Anh Huy Phan
RIKEN - BSI