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:
3 maximum values in a matrix

Subject: 3 maximum values in a matrix

From: Aidy

Date: 3 Jan, 2011 18:37:21

Message: 1 of 3

Hello friends,

I would like to ask for some help, if possible.

I have a matrix :

A = [ 12 45 6 89 55]

How can I get an output that returns the 3 values that are the highest such that my answer would be:

result = [0 45 0 89 55]

please assist if you can.

take care
aidy

Subject: 3 maximum values in a matrix

From: Sean de

Date: 3 Jan, 2011 19:00:25

Message: 2 of 3

"Aidy" wrote in message <ift511$1f8$1@fred.mathworks.com>...
> Hello friends,
>
> I would like to ask for some help, if possible.
>
> I have a matrix :
>
> A = [ 12 45 6 89 55]
>
> How can I get an output that returns the 3 values that are the highest such that my answer would be:
>
> result = [0 45 0 89 55]
>
> please assist if you can.
>
> take care
> aidy

Asorted = sort(A(:),'descend');
result = Asorted(1:3);

Subject: 3 maximum values in a matrix

From: Husam Aldahiyat

Date: 3 Jan, 2011 19:05:05

Message: 3 of 3

"Aidy" wrote in message <ift511$1f8$1@fred.mathworks.com>...
> Hello friends,
>
> I would like to ask for some help, if possible.
>
> I have a matrix :
>
> A = [ 12 45 6 89 55]
>
> How can I get an output that returns the 3 values that are the highest such that my answer would be:
>
> result = [0 45 0 89 55]
>
> please assist if you can.
>
> take care
> aidy

Does this work?

[o1,o2] = sort(A);
A(o2(1:end-3))=0

Tags for 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