MATLAB: If i have two binary matrix how can calculate the similarities between them

functionmatrixmatrix array

If i have (n,m) matrix M
M = [ 1 0 1 1 0 1
0 1 1 0 0 1
0 0 1 0 1 0
1 1 1 1 0 0]
And after some operation i found this two matrix which every one shows the number of group of ones in each row and in each column
M_row = [ 1 2 1
2 1 0
1 1 0
4 0 0 ]
M_col = [ 1 1 0 1 0
1 1 4 1 2 ]
After that generate a random matrix X in same size of M and then calculate the X_row and X_col like Matrix M
After that i need some way or a function to determine the similarities between M and X using the M_row ,M_col , X_row and X_col

Best Answer

if isequal(M_row, X_row) && isequal(M_col, X_col)
similarity = 1;
else
similarities = {'purple', 'tuba', 'beer', 'tardigrade', 'top quark'};
similarity = similarities{randi(length(similarities))};
end