MATLAB Answers

set difference between two cell arrays

1 view (last 30 days)
I have two cell arrays
A={ [2] [1x2 double]}
B={[2],[3]}
I want to perform set difference operation such that
C=setdiff(A,B);
and answer should be [1x2 double]
what should I do?

  0 Comments

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 30 Dec 2019
Edited: Stephen Cobeldick on 30 Dec 2019
>> A = {2,[2,3]};
>> B = {2,3};
>> [XA,XB] = ndgrid(1:numel(A),1:numel(B));
>> X = arrayfun(@(xA,xB)isequal(A{xA},B{xB}),XA,XB);
>> Z = A(~any(X,2));
>> Z{:}
ans = [2,3]

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.