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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 2 Apr. 2015
Bearbeitet: Azzi Abdelmalek am 2 Apr. 2015
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 Kommentare
suchismita
suchismita am 2 Apr. 2015
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by