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);
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
Dan, I suggest you use MATLAB's extensive 'help' command.
If you don't understand the blkproc function, just type
'help blkproc' at the prompt. In fact, before reading this
thread, I didn't understand it either, and now I can see
exactly how it works by using the help function.
In words, it goes through a matrix and finds the second
highest value in every row. The blkproc function call could
be replaced with a for loop going through every row to find
the second highest value, but I'm guessing it's more
efficient (and elegant) to take this approach.
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.
Dan <dan_ang_25@yahoo.com> wrote in message
<2717819.1199978159764.JavaMail.jakarta@nitrogen.mathforum.org>...
> Thks Huy & Clarkson alot. A bow to you all.
>
> i have acheived and understand it. And spending time to
solve my codes. I learnt something new today.
>
>
> Anyway, one last question is there any ways i can
identify the 2nd max value, which column is it taken from.
Eg. its from column 1, 2 , 3 ,4 or 5.
Suppose that you want to find the 2nd max value in the
column 1, 3 and 4
Dan <dan_ang_25@yahoo.com> wrote in message
<30744347.1200023064740.JavaMail.jakarta@nitrogen.mathforum.org>...
> :( ... i do not have maxnd function, is there any other
way out? Thks Huy. or anywwhere i can download this
function
Just copy and save the below code to a funtion file maxnd.m
function y = maxnd(x,n)
[xu,ind] = unique(x);
y = [xu(end-n+1) ind(end-n+1)];
Anh Huy Phan
RIKEN - BSI
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
What are tags?
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.