How to compare between two cell array?
조회 수: 23 (최근 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?
댓글 수: 0
채택된 답변
JESUS DAVID ARIZA ROYETH
2019년 12월 11일
answer=cell2mat(cellfun(@(x) any(cellfun(@(y) isequal(x,y),W)),F,'uni',false))
댓글 수: 6
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!