1

I have two cell arrays. I need to calculate the fraction of elements in the first cell array that do not occur in the second cell array. The elements in the cell array will be very large so a loop will take rather long, is there any way of doing this efficient? Below is a miniature example.

x = {'a b' ;'b c' ;'c d'} 
y = {'1 a' ;'a b' ;'b d'} 

I've tried to do cellfun(@strcmp, x, y) but this compare element by element when x and y are of same size. Instead I need to check if 'a b' is in y, etc for each element in x. This answer to the above should give 2/3, meaning 2 elements out of 3 are not in the y cell array.

Any vectorized ideas?

1 Answer 1

1

You want ismember:

>> notIn = ~ismember(x,y)
notIn =
     0
     1
     1

The fraction is thus sum(notIn)/numel(x).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.