Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Find N maximum values in an array

Subject: Find N maximum values in an array

From: Athanasios

Date: 19 Feb, 2010 18:37:04

Message: 1 of 2

I have an array with M values and i want to find the N maximum values as well their indices..Any help?

Subject: Find N maximum values in an array

From: Sadik

Date: 20 Feb, 2010 01:38:05

Message: 2 of 2

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);

Best.

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

Tags for this Thread

No tags are associated with this thread.

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.

Contact us