Got Questions? Get Answers.
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:
Behavior of built-in min function

Subject: Behavior of built-in min function

From: Filoche

Date: 18 Aug, 2010 14:07:21

Message: 1 of 4

Hi everyone.

For my personal information, I would like how the MIN function works when comparing 2 vectors.

For instance,

a = [1 2 3 4 5 6 7 8];
b = [1 2 3 4 5 6 7 18];

minvector = min(a,b);

will return vector a as the minimum vector.

However, I don't understand how this work. Does Matlab compute the mean of each vector and then return the smallest one?

Best regards,
Phil

Subject: Behavior of built-in min function

From: EE Student

Date: 18 Aug, 2010 14:27:34

Message: 2 of 4

Filoche <pmassicotte@hotmail.com> wrote in message <1580672501.24131.1282140471449.JavaMail.root@gallium.mathforum.org>...
> Hi everyone.
>
> For my personal information, I would like how the MIN function works when comparing 2 vectors.
>
> For instance,
>
> a = [1 2 3 4 5 6 7 8];
> b = [1 2 3 4 5 6 7 18];
>
> minvector = min(a,b);
>
> will return vector a as the minimum vector.
>
> However, I don't understand how this work. Does Matlab compute the mean of each vector and then return the smallest one?
>
> Best regards,
> Phil

Phil,

The min function is comparing each element within the 2 vectors. If size(a) ~= size(b) you will get an error unless one value is a scaler. Also note that if you were to input min (a,fliplr(b)) the result would be much different.

Subject: Behavior of built-in min function

From: Andy

Date: 18 Aug, 2010 14:28:28

Message: 3 of 4

Filoche <pmassicotte@hotmail.com> wrote in message <1580672501.24131.1282140471449.JavaMail.root@gallium.mathforum.org>...
> Hi everyone.
>
> For my personal information, I would like how the MIN function works when comparing 2 vectors.
>
> For instance,
>
> a = [1 2 3 4 5 6 7 8];
> b = [1 2 3 4 5 6 7 18];
>
> minvector = min(a,b);
>
> will return vector a as the minimum vector.
>
> However, I don't understand how this work. Does Matlab compute the mean of each vector and then return the smallest one?
>
> Best regards,
> Phil

It's comparing each element and choosing the smallest. It happens to be the case in your example that the elements of a are always the smallest. Perhaps the following will be more instructive:

a = [1 2 3 4 5 6 7 8];
b = [0 3 2 5 4 18 6 9];
min(a,b)

Subject: Behavior of built-in min function

From: Filoche

Date: 18 Aug, 2010 14:52:40

Message: 4 of 4

Hi Andy.

I do now understand how this is working.

Your example was perfect.

With regards,
Phil


Message was edited by: Filoche

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