How to make difference between two cell array?

조회 수: 1 (최근 30일)
Mira le
Mira le 2019년 12월 2일
답변: Matt J 2019년 12월 2일
>> NS
NS =
11×1 cell array
[ 1]
[ 2]
[ 3]
[ 4]
[ 5]
[1×2 double]
[1×2 double]
[1×2 double]
[1×2 double]
[1×3 double]
[1×3 double]
>> setL
setL =
1×7 cell array
[1] [2] [3] [4] [1×2 double] [1×2 double] [1×2 double]
I want to obtain element that contains in NS and not in setL
  댓글 수: 2
Rik
Rik 2019년 12월 2일
You mean something like setdiff?
Mira le
Mira le 2019년 12월 2일
yes, but how can I use sediff in cell array?

댓글을 달려면 로그인하십시오.

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 12월 2일
solution:
NSbutnotsetL=NS(~cellfun(@(y) any(cellfun(@(x) isequal(x,y),setL)),NS))
  댓글 수: 1
Mira le
Mira le 2019년 12월 2일
Thank you very much, it's really works

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2019년 12월 2일
fun=@(c) num2str(c,'%.20d ');
A=cellfun(fun,NS,'uni',0);
B=cellfun(fun,setL,'uni',0);
[~,ia]=setdiff(A,B);
result=NS(ia)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by