Correlation between two row matrices

3 vues (au cours des 30 derniers jours)
Bhaskar R
Bhaskar R le 9 Mai 2019
Commenté : gonzalo Mier le 9 Mai 2019
I am trying to do correlation between two row matrices but i am getting all NaN?
a = [-1 -1 -1 -1 -1 1 1 1 1 1];
b = randn(1,10);
result = corr(a, b);
result =
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

Réponse acceptée

gonzalo Mier
gonzalo Mier le 9 Mai 2019
Like that, each value of "a" is correlated to each value of "b", but applying the formula of the correlation, the correlation of two single numbers is NaN. To compute the correlation correctly, traspose the input vectors
result = corr(a', b');
  2 commentaires
Bhaskar R
Bhaskar R le 9 Mai 2019
Thank you gonzalo Mier
gonzalo Mier
gonzalo Mier le 9 Mai 2019
You're welcome :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by