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

조회 수: 2 (최근 30일)
suchismita
suchismita 2015년 4월 2일
댓글: suchismita 2015년 4월 2일
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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by