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

조회 수: 2 (최근 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