Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The following script finds the correlation between each pair of data.

clear all
LName={'Name1','Name2','Name3','Name4','Name5'};
Data={rand(12,1),rand(12,1),rand(12,1),rand(12,1),rand(12,1)};
%place in a structure
d = [LName;Data];
Data = struct(d{:});

d1 = cell2mat(struct2cell(Data)');
[R,P] = corrcoef(d1);
Correlation = [LName(nchoosek(1:length(R),2)) num2cell(nonzeros(tril(R,-1)))]

Furthermore, the script also states in 'Correlation' which combination of data was used in generating the correlation value. From this I am attempting to not only find the correlation between a pair of data but also find the correlation between n number of data, so in addition to the script above I'm trying to find the correlation between 3 sets of data, and then four... and so on, then store this in Correlation. How would I acheive this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
168 views
Welcome To Ask or Share your Answers For Others

1 Answer

Since your numbers are all non-negative I think simply multiplying the relevant arrays together, summing, and normalizing would be sufficient. This is basically the same thing that corrcoef does, except it only multiplies two arrays together at a time.

Please note, though, that this wouldn't work for negative numbers. For instance, imagine that all three arrays have a negative value at some point. This would be good, in the sense that they are well correlated. Simply multiplying them, though, would give you a negative correlation, which would indicate opposite correlation at that point.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...