From: Ulrik Nash on
Hi Everyone,

Suppose I have a matrix

A = [1 3 4 6; 10 9 30 23]

now I wish to perform an operation, so that I create

B = [3 9]

Note that B contains the column of A where the second row value is smallest.

How is this done?

Ulrik.
From: Oleg Komarov on
"Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <i14c5h$b73$1(a)fred.mathworks.com>...
> Hi Everyone,
>
> Suppose I have a matrix
>
> A = [1 3 4 6; 10 9 30 23]
>
> now I wish to perform an operation, so that I create
>
> B = [3 9]
>
> Note that B contains the column of A where the second row value is smallest.
>
> How is this done?
>
> Ulrik.

B = A(:,min(A(2,:)) == A(2,:)).'

Oleg
From: dpb on
Ulrik Nash wrote:
> Hi Everyone,
>
> Suppose I have a matrix
> A = [1 3 4 6; 10 9 30 23]
>
> now I wish to perform an operation, so that I create
>
> B = [3 9]
>
> Note that B contains the column of A where the second row value is
> smallest.
>
> How is this done?

[dum,idx]=min(A(2,:)); B=A(:,idx);

--
From: Ulrik Nash on
"Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <i14ge9$90c$1(a)fred.mathworks.com>...
> "Ulrik Nash" <uwn(a)sam.sdu.dk> wrote in message <i14c5h$b73$1(a)fred.mathworks.com>...
> > Hi Everyone,
> >
> > Suppose I have a matrix
> >
> > A = [1 3 4 6; 10 9 30 23]
> >
> > now I wish to perform an operation, so that I create
> >
> > B = [3 9]
> >
> > Note that B contains the column of A where the second row value is smallest.
> >
> > How is this done?
> >
> > Ulrik.
>
> B = A(:,min(A(2,:)) == A(2,:)).'
>
> Oleg

Thanks Oleg, much appreciated!
From: Steven Lord on

"dpb" <none(a)non.net> wrote in message
news:i14h3i$hk7$1(a)news.eternal-september.org...
> Ulrik Nash wrote:
>> Hi Everyone,
>>
>> Suppose I have a matrix
>> A = [1 3 4 6; 10 9 30 23]
>>
>> now I wish to perform an operation, so that I create
>>
>> B = [3 9]
>>
>> Note that B contains the column of A where the second row value is
>> smallest.
>>
>> How is this done?
>
> [dum,idx]=min(A(2,:)); B=A(:,idx);

I just want to call out, in case the OP didn't notice this, that Oleg's
solution will return _all_ columns that have the second row's minimum value
in their second row, while dpb's will contain only the first. Which is
appropriate, or whether this makes any difference at all, depends on the
OP's problem and data.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com