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:
ismember related problem

Subject: ismember related problem

From: Wendy

Date: 2 May, 2010 12:49:04

Message: 1 of 5

Hi all,

I have two cell arrays,

A = {'IFNG' 'IFNGR2'
'IFNW1' 'IFNAR1'
'IGF1' 'IGF1R'
'IHH' 'PTCH1'
'IL10' 'IL10RA '
'IL10' 'IL10RB'
'IL11' 'IL11RA'};

B = {'IL11' 'IL11FA'
'IHH' 'PTCH1'
'IHH' 'PTCH2'
'IL6' 'IL6RA'
'IFNG' 'IFNGR2'};

I want to find the rows of A that have the same elements as B and remove rows in A that do not have the same elements as B. To do that I used
K>> [tf_col_1 loc_col_1]=ismember(A(:,1),B(:,1));
K>> [tf_col_2 loc_col_2]=ismember(A(:,2),B(:,2));
output = ((loc_col_1==loc_col_2)&(loc_col_1~=0));
output=~output;
A(output,:) = [];

However, the second row of B, {'IHH' 'PTCH1'} (row4 in matrix A) cannot be picked up as the same row elements, as ismember '[tf_col_2 loc_col_2]=ismember(A(:,2),B(:,2));' only returns the largest index number which is 5. The row number is therefore not equal to the row number of 'PTCH1' in matrix A. I understand the function, ismember only return the largest index number, but does anybody know how to get around which the index issue, or have any suggested way of doing my problem?

Thank you,
Wendy

Subject: ismember related problem

From: us

Date: 2 May, 2010 13:04:03

Message: 2 of 5

"Wendy " <wlq121@gmail.com> wrote in message <hrjsc0$504$1@fred.mathworks.com>...
> Hi all,
>
> I have two cell arrays,
>
> A = {'IFNG' 'IFNGR2'
> 'IFNW1' 'IFNAR1'
> 'IGF1' 'IGF1R'
> 'IHH' 'PTCH1'
> 'IL10' 'IL10RA '
> 'IL10' 'IL10RB'
> 'IL11' 'IL11RA'};
>
> B = {'IL11' 'IL11FA'
> 'IHH' 'PTCH1'
> 'IHH' 'PTCH2'
> 'IL6' 'IL6RA'
> 'IFNG' 'IFNGR2'};
>
> I want to find the rows of A that have the same elements as B and remove rows in A that do not have the same elements as B. To do that I used
> K>> [tf_col_1 loc_col_1]=ismember(A(:,1),B(:,1));
> K>> [tf_col_2 loc_col_2]=ismember(A(:,2),B(:,2));
> output = ((loc_col_1==loc_col_2)&(loc_col_1~=0));
> output=~output;
> A(output,:) = [];
>
> However, the second row of B, {'IHH' 'PTCH1'} (row4 in matrix A) cannot be picked up as the same row elements, as ismember '[tf_col_2 loc_col_2]=ismember(A(:,2),B(:,2));' only returns the largest index number which is 5. The row number is therefore not equal to the row number of 'PTCH1' in matrix A. I understand the function, ismember only return the largest index number, but does anybody know how to get around which the index issue, or have any suggested way of doing my problem?
>
> Thank you,
> Wendy

a hint:
- run it both ways...

     [imab,ixab]=ismember(a,b);
     [imba,ixba]=ismember(b,a);
% then collect memberships and prune the mats...

us

Subject: ismember related problem

From: dpb

Date: 2 May, 2010 13:15:39

Message: 3 of 5

Wendy wrote:
...
> I have two cell arrays,
> A = {'IFNG' 'IFNGR2'
> 'IFNW1' 'IFNAR1'
> 'IGF1' 'IGF1R'
> 'IHH' 'PTCH1'
> 'IL10' 'IL10RA '
> 'IL10' 'IL10RB'
> 'IL11' 'IL11RA'};
>
> B = {'IL11' 'IL11FA'
> 'IHH' 'PTCH1'
> 'IHH' 'PTCH2'
> 'IL6' 'IL6RA'
> 'IFNG' 'IFNGR2'};
>
> I want to find the rows of A that have the same elements as B and remove
> rows in A that do not have the same elements as B. ...

I'm not positive I follow which you want to keep and which to remove,
but I'm guessing...

 >> inA=ismember(A,B);
 >> inArow=inA(:,1)&inA(:,2)==1;
 >> C=A(inArow,:)
C =
     'IFNG' 'IFNGR2'
     'IHH' 'PTCH1'
 >>

If later versions of ML support the 'rows' option in ismember() that
would seem to be the cat's meow...(???)

--

Subject: ismember related problem

From: dpb

Date: 2 May, 2010 13:30:46

Message: 4 of 5

dpb wrote:
...

> If later versions of ML support the 'rows' option [for cell arrays] in ismember() ...

--

Subject: ismember related problem

From: Bruno Luong

Date: 2 May, 2010 14:01:06

Message: 5 of 5

"Wendy " <wlq121@gmail.com> wrote in message <hrjsc0$504$1@fred.mathworks.com>...
> Hi all,
>
> I have two cell arrays,
>
> A = {'IFNG' 'IFNGR2'
> 'IFNW1' 'IFNAR1'
> 'IGF1' 'IGF1R'
> 'IHH' 'PTCH1'
> 'IL10' 'IL10RA '
> 'IL10' 'IL10RB'
> 'IL11' 'IL11RA'};
>
> B = {'IL11' 'IL11FA'
> 'IHH' 'PTCH1'
> 'IHH' 'PTCH2'
> 'IL6' 'IL6RA'
> 'IFNG' 'IFNGR2'};
>
> I want to find the rows of A that have the same elements as B and remove rows in A that do not have the same elements as B. To do that I used
> K>> [tf_col_1 loc_col_1]=ismember(A(:,1),B(:,1));
> K>> [tf_col_2 loc_col_2]=ismember(A(:,2),B(:,2));
> output = ((loc_col_1==loc_col_2)&(loc_col_1~=0));
> output=~output;
> A(output,:) = [];
>

Why bother with loc at all? This should do what you want:

A = A(ismember(A(:,1),B(:,1)) & ismember(A(:,2),B(:,2)),:)

Bruno

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