MATLAB: How to find correlation between the row values of a matrix

matrixmatrix arraymatrix manipulation

I have a matrix D, which consists of 5 rows and 5 columns. The elements of matrix are 1 or 0. I name each row as S1, S2, S3, S4 and S5. I want to find the correlation betwwen the row values of matrix. for example,
D=[1 1 0 0 1;1 0 0 0 0;1 1 1 1 0;0 0 0 1 0;0 1 1 1 1]
S1=[1 1 0 0 1]
S2=[1 0 0 0 0]
S3=[1 1 1 1 0]
S4=[0 0 0 1 0]
S5=[0 1 1 1 1]
first i want to find correlation between first two rows as, condition is if both rows are having 1 1 or 0 0 then we count otherwise we dont. So,
{S1,S2}=3 from the above example
{S1,S3}=2
{S1,S4}=1
{S1,S5}=2
{S2,S3}=2 \\we wont calculate for {S2,S1} as {S1,S2} is already done
{S2,S4}=3
{S2.S5}=0
{S3,S4}=2
{S3,S5}=3
{S4,S5}=2
please help in doing the coding how shall i make the pairs, it will be a great help, please eagerly waiting for your response.

Best Answer

D=[1 1 0 0 1;1 0 0 0 0;1 1 1 1 0;0 0 0 1 0;0 1 1 1 1]
for k=1:size(D,1)-1
res{k}=sum(bsxfun(@eq,D(k+1:end,:),D(k,:)),2)
end
celldisp(res)