# How to compare the values of 2 arrays vs each other?

125 views (last 30 days)
ESIDOR PASHAJ on 8 Mar 2018
Commented: ESIDOR PASHAJ on 8 Mar 2018
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.

njj1 on 8 Mar 2018
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
ESIDOR PASHAJ on 8 Mar 2018
I worked around your answer and got to where I wanted to get. Thank you very much.