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 that are not repeated

Subject: Extract numbers that are not repeated

From: Aidy

Date: 11 Dec, 2010 02:25:05

Message: 1 of 4

Good day folks,

I am given 2 matrices X and Y:

X =
                 100 220 300 400
                 300 400 650 975
                 300 400 111 348
                 567 432 300 400
                 123 549 200 800
                 200 800 709 846

Y = 300 400
               200 800

Y is matrix whose rows represent numbers that are repeated more than once in rows of X. For any rows in Y, they can be repeated in X , a maximum of 4 times as seen for example with ' 300 400' and a minimum of 2 times as seen with ' 200 800'

How can I output the following matrix ? :

output =
                    100 220
                    650 975
                    111 348
                    567 342
                    123 549
                    709 846

Can anyone help me out on this?

regards,
Aiden

                 
                 

Subject: Extract numbers that are not repeated

From: dpb

Date: 11 Dec, 2010 15:15:01

Message: 2 of 4

Aidy wrote:
> Good day folks,
>
> I am given 2 matrices X and Y:
>
> X = 100 220 300 400
> 300 400 650 975
> 300 400 111 348
> 567 432 300 400
> 123 549 200 800
> 200 800 709 846
>
> Y = 300 400
> 200 800
>
> Y is matrix whose rows represent numbers that are repeated more than
> once in rows of X. For any rows in Y, they can be repeated in X , a
> maximum of 4 times as seen for example with ' 300 400' and a minimum of
> 2 times as seen with ' 200 800'
>
> How can I output the following matrix ? :
>
> output = 100 220
> 650 975
> 111 348
> 567 342
> 123 549
> 709 846
>
> Can anyone help me out on this?
...
 >> idx=~ismember(X,Y)
idx =
      1 1 0 0
      0 0 1 1
      0 0 1 1
      1 1 0 0
      1 1 0 0
      0 0 1 1
 >>

If all you need is the values, X(idx) works.

If you need to keep the shape, takes some more effort. Starting with
remembering Matlab is column-major ordering...

 >> T=X';Q=T(~ismember(T,Y)); % transpose X for starters...
 >> z=reshape(Q,2,6)'
z =
    100 220
    650 975
    111 348
    567 432
    123 549
    709 846
 >>

--

Subject: Extract numbers that are not repeated

From: Ahmed Fasih

Date: 11 Dec, 2010 15:19:05

Message: 3 of 4

> I am given 2 matrices X and Y:
>
> X =
> 100 220 300 400
> 300 400 650 975
> 300 400 111 348
> 567 432 300 400
> 123 549 200 800
> 200 800 709 846
>
> Y = 300 400
> 200 800
>
> Y is matrix whose rows represent numbers that are repeated more than once in rows of X. For any rows in Y, they can be repeated in X , a maximum of 4 times as seen for example with ' 300 400' and a minimum of 2 times as seen with ' 200 800'
>
> How can I output the following matrix ? :
>
> output =
> 100 220
> 650 975
> 111 348
> 567 342
> 123 549
> 709 846

I was confused by the sizes of X and Y, but I'm assuming that both X and Y are just vectors.

help setdiff

output = setdiff(X(:), Y(:))

Subject: Extract numbers that are not repeated

From: Aidy

Date: 11 Dec, 2010 18:27:04

Message: 4 of 4

dpb ,

thanks a lot.

aidy

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