compare cells discriminating the order and empty cells

1 次查看(过去 30 天)
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 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by