Info

This question is closed. Reopen it to edit or answer.

How do I do correlation coefficient within a matrix?

1 view (last 30 days)
Lakyn
Lakyn on 25 Aug 2016
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello!
So I understand how to use the built in correlation coefficient, but it does not work for me. My scenario is that I have a 76x4000 matrix, and I want to find the correlation coefficient among each of the 76 rows, so i = 1:76, j = 1:76.
The end result should be a 76x76 symmetric matrix with 1s in the diagonal line.
Thank you very much!
I already have some codes for it, but the results are evidently wrong because I compared it to how it should be.
function Z = correlationcoefficient(P)
Z = []
for i = 1:76
% T = [];
for j = 1:76
w = 0;
s = cov(P(i,:),P(j,:));
t = s(1,2);
u = std(P(i,:));
v = std(P(j,:));
w = t/(u*v);
Z(j,i) = w;
end
end
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!