Correlation between two row matrices

3 Ansichten (letzte 30 Tage)
Bhaskar R
Bhaskar R am 9 Mai 2019
Kommentiert: gonzalo Mier am 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

Akzeptierte Antwort

gonzalo Mier
gonzalo Mier am 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 Kommentare
Bhaskar R
Bhaskar R am 9 Mai 2019
Thank you gonzalo Mier
gonzalo Mier
gonzalo Mier am 9 Mai 2019
You're welcome :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by