MATLAB Answers


Plot the Bivariate Gaussian pdf

Asked by Ben Turi on 15 Sep 2018 at 21:45
Latest activity Answered by Jeff Miller on 16 Sep 2018 at 18:36

I'm trying to plot the Bivariate Gaussian pdf with zero mean and covariance (6, 2; 2,2), but I'm coming up with a weird error. Here is my code:

mu = 0
covariance = [6 2; 2 2]
norm = normpdf(R,mu,covariance)

But I get this as an error:

Error using normpdf (line 36)
Non-scalar arguments must match in size.

How can I properly plot the pdf with the specified covariance? As a side note, the variable R comes from a earlier established normal variable with mean of 5 and variance of 30 (randn(5, 30))

Thanks for your time and help in advanced! I really appreciate it!


Sign in to comment.

1 Answer

Answer by Jeff Miller on 16 Sep 2018 at 18:36

normpdf is the univariate normal pdf. You need mvnpdf, which is the multivariate version. Also, plot will not produce a 3d plot. See multivariate normal . The first example seems pretty close to what you want.


Sign in to comment.