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:
isolating a column based in a matrix

Subject: isolating a column based in a matrix

From: Ulrik Nash

Date: 8 Jul, 2010 11:18:09

Message: 1 of 5

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.

Subject: isolating a column based in a matrix

From: Oleg Komarov

Date: 8 Jul, 2010 12:31:05

Message: 2 of 5

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <i14c5h$b73$1@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

Subject: isolating a column based in a matrix

From: dpb

Date: 8 Jul, 2010 12:39:50

Message: 3 of 5

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);

--

Subject: isolating a column based in a matrix

From: Ulrik Nash

Date: 8 Jul, 2010 12:44:05

Message: 4 of 5

"Oleg Komarov" <oleg.komarovRemove.this@hotmail.it> wrote in message <i14ge9$90c$1@fred.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <i14c5h$b73$1@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!

Subject: isolating a column based in a matrix

From: Steven Lord

Date: 8 Jul, 2010 13:24:47

Message: 5 of 5


"dpb" <none@non.net> wrote in message
news:i14h3i$hk7$1@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@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

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