set difference between two cell arrays

조회 수: 8 (최근 30일)
Niharika  Nayak
Niharika Nayak 2019년 12월 30일
댓글: Niharika Nayak 2019년 12월 30일
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?

채택된 답변

Stephen23
Stephen23 2019년 12월 30일
편집: Stephen23 2019년 12월 30일
>> 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]

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by