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

1 回表示 (過去 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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by