how to find correlation between the row values of a matrix?

2 次查看(过去 30 天)
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.

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2015-4-2
编辑:Azzi Abdelmalek 2015-4-2
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)
  4 个评论
suchismita
suchismita 2015-4-2
yes sir....
if i want to find correlation between for example
{S1,S2,S3} {S1,S2,S4} {S1,S2,S5} {S2,S3,S4} {S2,S3,S5} {S3,S4,S5}
its like i am making subsets of a matrix... i am trying with the above code but not able to implement

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by