Mvnpdf says my sigma is not a covariance matrix. Not sure what's wrong.

5 views (last 30 days)
Carleen McKenna
Carleen McKenna on 3 Nov 2021
Commented: Carleen McKenna on 3 Nov 2021
I am trying to fit a bivariate normal distribution to 10 million datapoints so I can plot the countours over the scatter plot. I used cov on them in order to get a covariance to use with mvnpdf, and this is the covariance I got:
cov_post60 = [0.034369349437442,2.471831619409349e-04;2.471831619409349e-04,3.905926731719625e-06]
But mvnpdf throws this error:
"SIGMA must be a square covariance matrix, the diagonal vector of a covariance matrix, or a 3-D array of covariance matrices or covariance diagonal vectors."
I've checked the cholesky decomposition and it exists. Checked the eigen values, and even though one is small on the order of e-6 they're both still positive. Checked cond(cov_post60) and it's well below 1/eps. But it's still telling me it isn't a covariance matrix and I'm not sure what's wrong. Is there something I'm missing? Like I said, I literally used cov to get that matrix, so how it could tell me it isn't one just baffles me.
Carleen McKenna
Carleen McKenna on 3 Nov 2021
Oh, of course, how embarassing. No wonder it was telling me it wasn't a covariance matrix when I had everything in the wrong places. I apologize for wasting your time on this, but thanks for your help. I had it in my head that mvnpdf had a certain syntax, and didn't even notice I was wrong when I looked up the documentation.

Sign in to comment.

Answers (0)




Community Treasure Hunt

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

Start Hunting!