From: Mano Samuel on

Hello,

Lets say I have a matrix, aa = [1 2 0;-1 0 6]

aa =

1 2 0
-1 0 6

If check the number of rows of aa , using size(aa,dim) , where dim is 1

size(aa,1)

ans =

2

It tells me there are two rows.

Fine. Now if I need to find the minimum value along the row dimension,

My mind tends to process it such that there are two rows, hence the output value would be the minimum value along each row.

so in the first row, 1 2 0,

the minimum value is 0 and ,

in the second row, -1 0 6

the minimum value is -1 .

MATLAB however offers,

[val,pos] = min(aa,[],1)

val =

-1 0 0


pos =

2 2 1

I understand the logic behind MATLAB, but why this way ? . Hope someone can help me understand this. Thank you.

Mano


From: Yi Cao on
"Mano Samuel" <manosamuel(a)rediffmail.com> wrote in message <hqovis$afu$1(a)fred.mathworks.com>...
>
> Hello,
>
> Lets say I have a matrix, aa = [1 2 0;-1 0 6]
>
> aa =
>
> 1 2 0
> -1 0 6
>
> If check the number of rows of aa , using size(aa,dim) , where dim is 1
>
> size(aa,1)
>
> ans =
>
> 2
>
> It tells me there are two rows.
>
> Fine. Now if I need to find the minimum value along the row dimension,
>
> My mind tends to process it such that there are two rows, hence the output value would be the minimum value along each row.
>
> so in the first row, 1 2 0,
>
> the minimum value is 0 and ,
>
> in the second row, -1 0 6
>
> the minimum value is -1 .
>
> MATLAB however offers,
>
> [val,pos] = min(aa,[],1)
>
> val =
>
> -1 0 0
>
>
> pos =
>
> 2 2 1
>
> I understand the logic behind MATLAB, but why this way ? . Hope someone can help me understand this. Thank you.
>
> Mano
>
>

Siize(aa,1) means the size of the first dimension, i.e. size of a column. Similarly, min(aa,[],1) is the minimum along the first dimension, which is the column, i.e. the minimum of columns.

HTH
Yi