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

1 次查看(过去 30 天)
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 个评论
the cyclist
the cyclist 2011-10-15
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 2011-10-16
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

请先登录,再进行评论。

采纳的回答

the cyclist
the cyclist 2011-10-16
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by