How to compare between two cell array?

27 次查看(过去 30 天)
>> W={ [1 2] , [1 3] , [1 4] , [2 3] , [2 4] }
W =
1×5 cell array
[1×2 double] [1×2 double] [1×2 double] [1×2 double] [1×2 double]
>> F={ [1 2] , [1 3] , [1 4] }
F =
1×3 cell array
[1×2 double] [1×2 double] [1×2 double]
I want to compare each value in F if it is exist in W?

采纳的回答

JESUS DAVID ARIZA ROYETH
answer=cell2mat(cellfun(@(x) any(cellfun(@(y) isequal(x,y),W)),F,'uni',false))
  6 个评论
Stephen23
Stephen23 2019-12-11
Simpler using indexing:
>> X = ismember(cat(1,F{:}),cat(1,W{:}),'rows');
>> cat(1,F{X})
ans =
1 2
1 4
>> cat(2,F{X})
ans =
1 2 1 4

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by