analyse the two cell arrays if they have different content b = {1;2;3;5} and a = {2;1;3;6} in matlab

You can compare the content of two cell arrays element-wise using the isequal() function. However, if the cell arrays have different number of elements, they are not considered equal. In your case, as a and b have different contents, and different number of elements, you can use the setxor() function to return the exclusive set of elements between a and b.

Here is an example code:

main.m
a = {2;1;3;6};
b = {1;2;3;5};

diff_ab = setxor(a,b) % returns {6,5}
69 chars
5 lines

In this case, the setxor() function results in a cell array that contains the unique elements present in a and b only, which are 6 and 5.

related categories

gistlibby LogSnag