How to calculate the correlation coefficient between an array and a matrix?

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.

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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];
>> corr(x,y)
ans =
0.9221 -0.1434
-0.2979 0.8438
0.6825 0.5606

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?

SEE COMPLETE ANSWER CLICK THE LINK

--

--

--

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Data Science 101 for Startups- Aggregation in SQL

This Will Make You Airbnb in Boston Efficiently.

Roadmap to Become a “Data Scientist”

New data added: Welcome to Estonia

New data added: Down Under

Machine-Learning Model Can Inform Quarantine Measures to Reduce the Spread of COVID-19

A-Star (A*) Search for Solving a Maze using Python (with visualization)

D4S Sunday Briefing #60

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

More from Medium

Main Challenges of Machine Learning in 2022

Flipping a Coin in Python

How I Learned the Basics of Python in 2 Weeks — rainswerld

Best Book to Quick Start Python Programming for Data Analysis