MATLAB: Histogram2 versus mvnpdf

histogram2joint pdfmvnpdf

I have two variables and would like to create a joint PDF. I am mainly interested in the shape of the PDF and not the actual probability. My variables are two column arrays: u and v. I first tried using histrogram2(u, v), but was unsure if that was the correct function to use. I then tried using the mvnpdf function to check. I tried JPDF = mvnpdf( [u ,v] ). I then plotted the result with scatter3(u,v,JPDF). I got a different shaped distribution curve than the histrogram2 curve. Can anyone explain why they would produce different shaped curves?

Best Answer

Hi,
The mvnpdf estimates the pdf value of each pair of variables with respect to zero mean and identity covariance matrix d-dimensional gaussian distribution where d is the number of variables. So, it uses the formula of multivariate normal distribution for calculation of those pdf values.
Whereas histogram2 just distributes the x and y variables as coordinates into the bins specified by the range of x and y variables and the number of bins.
So, the difference between the two is mvnpdf will give exact value according to multivariate normal distribution only while histogram2 will give the exact shape of the distribution based on the count of variables in specific range. For getting exact shape it requires data to be coming to all bins in histogram2 and there are enough instances of variable representing the distribution accurately.