How do I compare two different cell arrays whose elements are NOT strings?
조회 수: 4 (최근 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!