How do I compare two different cell arrays whose elements are NOT strings?
6 次查看(过去 30 天)
显示 更早的评论
I have two cell arrays, A and B, each of which is filled with matrices of differing values. If I want all elements in B that are not in A, how would I find that? (say A{1,1} = B{1,1} but A{2,1} ~= B{2,1}, how could I have matlab return this?) I tried using setdiff but matlab returned an error saying that setdiff only deals with cell arrays of strings.
I need to use a cell array to save these matrices as they are matrices of different sizes.
0 个评论
回答(1 个)
Image Analyst
2015-7-5
You can loop over corresponding cells and use isequal to check:
if isequal(A{rowa, cola}, B{rowb, colb})
% Cell contents are equal.
else
% Cell contents are not equal.
end
Of course rowa might be the same as rowb as you seem to indicate, but it might not be, particularly if A and B don't have the same number of cells in them. It just depends on what cell of A you're comparing to what cell of B.
Now take some action depending on whether the cell contents are equal or not.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!