Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

correlation in matlab

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...