How do I compare two different cell arrays whose elements are NOT strings?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Image Analyst
le 5 Juil 2015
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 commentaires
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!