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:
extract numbers which are -1

Subject: extract numbers which are -1

From: Kate

Date: 13 Dec, 2010 18:42:06

Message: 1 of 3

Hi guys,

I have two matrices:

D = [ 1; -1 ; -1 ;1]
A = [ 20 40 ; 30 35 ; 50 90 ; 100 200 ]

How can I extract the rows in 'A' that correspond to -1 values in D such that I would be able to return:

return = [ 30 35; 50 90]

thanks
kate

Subject: extract numbers which are -1

From: Sean de

Date: 13 Dec, 2010 18:49:06

Message: 2 of 3

"Kate " <chino_tones@hotmail.com> wrote in message <ie5pdu$oa5$1@fred.mathworks.com>...
> Hi guys,
>
> I have two matrices:
>
> D = [ 1; -1 ; -1 ;1]
> A = [ 20 40 ; 30 35 ; 50 90 ; 100 200 ]
>
> How can I extract the rows in 'A' that correspond to -1 values in D such that I would be able to return:
>
> return = [ 30 35; 50 90]
>
> thanks
> kate


A(D==-1,:)

Subject: extract numbers which are -1

From: dpb

Date: 13 Dec, 2010 18:51:10

Message: 3 of 3

Kate wrote:
> Hi guys,
>
> I have two matrices:
>
> D = [ 1; -1 ; -1 ;1]
> A = [ 20 40 ; 30 35 ; 50 90 ; 100 200 ]
>
> How can I extract the rows in 'A' that correspond to -1 values in D such
> that I would be able to return:
>
> return = [ 30 35; 50 90]
>

Pretty trivially; did you even try on this one????

A(D==-1,:)

--

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