How to make difference between two cell array?

1 次查看(过去 30 天)
>> 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

采纳的回答

JESUS DAVID ARIZA ROYETH
solution:
NSbutnotsetL=NS(~cellfun(@(y) any(cellfun(@(x) isequal(x,y),setL)),NS))

更多回答(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