compare cells discriminating the order and empty cells

조회 수: 1 (최근 30일)
jennifer modamio
jennifer modamio 2017년 5월 9일
편집: Stephen Jue 2017년 5월 12일
Hi, how could I compare cell(1024x6) with another (same size), comparing row by row. Avoiding problems with empty cells and not finding differences because of the order of the components. ex:
(a, cell 1x4) '10FTHF5GLUtm' '10fthf5glu[m] '[] []
(b, cell 1x4) '10FTHF5GLUtm' '10fthf5glu[m] '[] []
ERROR: (because of the empty cells)
(a, cell 1x4) ' *10fthf5glu[m]'* '10FTHF5GLUtm' [] []
(b, cell 1x4) '10FTHF5GLUtm' ' *10fthf5glu[m]'*[] []
difference found because the order of the cells is different despite the content is the same** I want to compare, without finding differences in this case. I would like to find differences only when the content inside the cell is different, but not because of the position.
Is there any way to do this?
Thanks!!

답변 (1개)

Stephen Jue
Stephen Jue 2017년 5월 12일
편집: Stephen Jue 2017년 5월 12일
Hi,
What you can do is filter out the empty cells from your arrays, then use the setdiff function to do a set difference between these two cell arrays. This ignores the order of the elements.
Note that this assumes that each cell array contains all unique elements. If this is not the case, you may need to use a different technique (e.g. sorting).
aFiltered = a(find(~cellfun(@isempty, a)));
bFiltered = b(find(~cellfun(@isempty, b)));
setdiff(aFiltered, bFiltered) % if this is empty, there is no difference.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by