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 all the minimum

Subject: Find all the minimum

From: Diego Zegarra

Date: 9 Nov, 2008 22:10:04

Message: 1 of 7

Hey guys I need your help on this, I need to find all the positions where a minimum value occur. Lets say,

A = [120;113;116;196;113];

When you try to find the minimum,

MinValue = min(A);

you get a result as,

MinValue = 113

Now I want to be able to get the 113 value plus know that it occurs at A(1,2) and at A(1,5). How can I do this??

Thank you so much for your help and I hope I made myself clear!

Diego

Subject: Find all the minimum

From: Diego Zegarra

Date: 9 Nov, 2008 22:49:01

Message: 2 of 7

Nevermind guys I found the solution to my question.

Just did,

Idxs = find(A==MinValue);

Thanks anyways!

Subject: Find all the minimum

From: aasim Azooz

Date: 10 Nov, 2008 00:41:02

Message: 3 of 7

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gf7pct$kld$1@fred.mathworks.com>...
> Nevermind guys I found the solution to my question.
>
> Just did,
>
> Idxs = find(A==MinValue);
>
> Thanks anyways!
The easy way is
[x,k]=min(A)

x is the minimum value
k is the index
See help min
Aasim Azooz

Subject: Find all the minimum

From: Walter Roberson

Date: 10 Nov, 2008 00:51:22

Message: 4 of 7

aasim Azooz wrote:
> "Diego Zegarra" <diegozbb@gmail.com> wrote in message <gf7pct$kld$1@fred.mathworks.com>...
>> Nevermind guys I found the solution to my question.
>>
>> Just did,
>>
>> Idxs = find(A==MinValue);
>>
>> Thanks anyways!
> The easy way is
> [x,k]=min(A)
>
> x is the minimum value
> k is the index
> See help min


Yes, see help min, which would show you that min() with two return arguments
only returns the index of the -first- minimum found (with respect to the
appropriate dimension.)


--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Find all the minimum

From: Diego Zegarra

Date: 10 Nov, 2008 01:18:01

Message: 5 of 7

hey Aasim thanks for your suggestion but that does not work as it will only give you the first value, so 113. However what I wanted was to get where that value was if it was at more than one place so in this case I wanted to know that it was at 2 and 5 and the code I gave does that.

Thanks

Subject: Find all the minimum

From: aasim Azooz

Date: 11 Dec, 2008 18:54:02

Message: 6 of 7

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gf8249$hob$1@fred.mathworks.com>...
> hey Aasim thanks for your suggestion but that does not work as it will only give you the first value, so 113. However what I wanted was to get where that value was if it was at more than one place so in this case I wanted to know that it was at 2 and 5 and the code I gave does that.
>
> Thanks

Hi
In that case you can use my programs maxima and minima. you can download them from matlab file exchange
good luck
Aasim

Subject: Find all the minimum

From: Neelabh

Date: 24 Apr, 2012 07:28:08

Message: 7 of 7

"Diego Zegarra" wrote in message <gf7n3s$1g7$1@fred.mathworks.com>...
> Hey guys I need your help on this, I need to find all the positions where a minimum value occur. Lets say,
>
> A = [120;113;116;196;113];
>
> When you try to find the minimum,
>
> MinValue = min(A);
>
> you get a result as,
>
> MinValue = 113
>
> Now I want to be able to get the 113 value plus know that it occurs at A(1,2) and at A(1,5). How can I do this??
>
> Thank you so much for your help and I hope I made myself clear!
>
> Diego

U can use

find(A==min(A))

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