Find correlation between two matrices with varying NaN coordinates
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello. I have global two matrices, A and B
They are both the same dimensions, but A has NaN's in some places that B does not. When I use corrcoef, it returns NaN's, even though the values within A and B are not identical. Is it returning NaN because the varying coordinates of NaN values within each matrix?
Does anyone know what I'm doing wrong in this case?
Thanks,
Melissa
0 Commenti
Risposte (1)
Chad Greene
il 18 Mag 2015
Indeed,
A = [1 2 3 4 5 6 7];
B = [1 2 2 4 5 6 NaN];
corrcoef(A,B)
ans =
1 NaN
NaN NaN
But if you consider only non-NaN data:
% indices of non-nan data:
realz = isfinite(A) & isfinite(B);
% correlation coefficient of non-nan data:
corrcoef(A(realz),B(realz))
ans =
1.0000 0.9786
0.9786 1.0000
0 Commenti
Vedere anche
Categorie
Scopri di più su Descriptive Statistics in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!