How do I compare two different cell arrays whose elements are NOT strings?
3 ビュー (過去 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!