How to calculate the correlation coefficient between an array and a matrix?
11 views (last 30 days)
Show older comments
Nut on 25 May 2016
Commented: Nut on 1 Jul 2016
I have a matrix A and a matrix B, with the same number of rows and a different number of columns. I need to calculate the correlation coefficient between each single columns of the matrix A and all the columns of the matrix B. For each column of A, the partial result will be an array, so I'm thinking to a matrix as final result.
Is there a way to do this avoiding the "for" cycle? Which is the most efficient way to do this? Could you suggest me the best syntax?
Finally, I have also to do the same with the mean squared error: again, in this second case, is it possible to avoid the "for" cycle?
Thanks for your answers.
Tom Lane on 24 Jun 2016
If you have the Statistics and Machine Learning Toolbox, it sounds like you want this:
>> x = randn(20,3);
>> y = x*[1 0;0 1;1 1];
I'm not sure what you mean by mean squared error. The following adds some noise to get z, then computes coefficients for predicting y from z, then computes the sum of squared differences between y and the predicted values for each column. Does this point you in the right direction?
>> z = x+randn(size(x))/100;
More Answers (0)
Find more on Correlation and Convolution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!