Azzera filtri
Azzera filtri

How do I use nancov on a a matrix that has multiple consecutive rows of NaN in some of the columns?

1 visualizzazione (ultimi 30 giorni)
I am trying to use nancov on a matrix that has multiple consecutive rows of NaN in some of the columns, and nancov simply returns a matrix full of zeros. (The NaN values are due to gaps in the data.) Any suggestions for alternatives or ways to get around this?
  2 Commenti
the cyclist
the cyclist il 15 Ott 2011
Are you able to show us the data (or a small subset) that exhibit the issue? Also, why do you think the result is incorrect? Could it be that the covariance is truly zero?
Jenny
Jenny il 16 Ott 2011
Below is an example matrix, when I have situations like column 2 or 3, it doesn't work. When I have situations like column 1, it works fine. I think the result is incorrect because if I manually change the NaN values and run it again, nancov works, by which I mean I don't get a matrix full of zeros. Also, I have other data sets like this that only have situations like column 1 and they work fine.
58.28 0.5798 7.833 -60.29 0.768 2.14
-4.235 NaN 68.08 NaN 0.9708 -6.435
-0.5155 NaN -4.611 0.4154 NaN 0.32
NaN NaN NaN 30.5 NaN 96.01
0.4329 -0.2091 NaN 8.744 4.387 NaN
-22.59 37.98 0.0592 150 -49.83 NaN

Accedi per commentare.

Risposta accettata

the cyclist
the cyclist il 16 Ott 2011
After removing the observations (i.e. rows) that have any NaNs in them, you are left with only one row. You can't take the covariance of a single observation.
I don't fully understand why MATLAB creates output of all zeros. (It seems like an output of NaN would be more appropriate.) But that's the underlying cause.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by