From: "Sadik " <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Find N maximum values in an array
Date: Sat, 20 Feb 2010 01:38:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <hlneds$8ej$>
References: <hlmlog$1re$>
Reply-To: "Sadik " <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1266629885 8659 (20 Feb 2010 01:38:05 GMT)
NNTP-Posting-Date: Sat, 20 Feb 2010 01:38:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: comp.soft-sys.matlab:609950

How about this?

Let your array be x.

[sortedX,sortingIndices]  = sort(x,'descend');

% sortedX will be in descending order. Therefore, the first N elements will be the N maximum values.

maxValues = sortedX(1:N);
maxValueIndices = sortingIndices(1:N);


"Athanasios " <> wrote in message <hlmlog$1re$>...
> I have an array with M values and i want to find the N maximum values as well their indices..Any help?