"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
