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 columnmajor 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
>>

