Use the following syntax to get the number of disparate characters for strings of the same size:
sum( str1 ~= str2 )
If you want to be case insensitive, use:
sum( lower(str1) ~= lower(str2) )
The expression str1 ~= str2 compares the char -by-char of two strings, giving a logical vector of the same size as the strings, with true where they do not match (using ~= ) and false where they match. To get the result, simply sum the number of true values (inconsistencies).
EDIT: if you want to count the number of matching characters:
Use the "equal to" == operator (instead of the "not equal" ~= operator):
sum( str1 == str2 )
Subtract the number of discrepancies from the total:
numel(str1) - sum( str1 ~= str2 )
source share