MATLAB: How to compare the values of 2 arrays vs each other

arrayscompareMATLAB

Hi guys, I am a bit of a noob at Matlab. What I want to do is compare the values of two arrays with each other to see what % similar are they? So, basically, if I have array A = (1,2,3,4) and array B = (1,2,5,6)…I would like to compare these two to each other using a function or something, and that function should state (in this case) that they are 50% similar. I would appreciate your help.

Best Answer

What do you mean by "similar"? If you want simply see the number of entries that are the same, then this could do the trick:
s = A==B; %this is a boolean vector that will be 1 if the entries are the same and 0 if different
similarity = sum(s)/numel(s); this is the number of entries that are equal divided by the total number of entries