1

How to plot standard deviation contours for a bivariate normal distribution (using MATLAB) showing only seven contours from 1-σ to 7-σ ?

mu=[2 3];     %mean
Sigma=[1 1];  %standard deviation
x1 = -10:.2:10;   
x2 = -10:.2:10;
[X1,X2] = meshgrid(x1,x2);
F=mvnpdf([X1(:) X2(:)],mu,Sigma);   %compute Gaussian pdf
F=reshape(F,length(x2),length(x1));
contour(x1,x2,F,'ShowText','on');  %Equally spaced contour

I do not need an equally spaced contour, but rather showing only seven contours from 1σ to 7σ

https://en.wikipedia.org/wiki/Multivariate_normal_distribution The green line (3-sigmas ellipse) in Figure 1 Probability Density Function in this link shows what I want to do, but I do not know how they did it. How to plot that green line ( 3-σ) and similar lines for different sigmas.

ASE
  • 1,702
  • 2
  • 21
  • 29
  • Have a look [here](http://stackoverflow.com/questions/3417028/ellipse-around-the-data-in-matlab) and [here](http://www.mathworks.com/matlabcentral/fileexchange/46324-gaussian-ellipses-constant-probability-curves/content/ellipsedata.m) – Miki Mar 02 '16 at 20:02

1 Answers1

0

This code I guess will do the job. It is based on tolerance intervals

mu = [2 3];
Sigma = [1 1];
x1 = -10:.2:10; x2 = -10:.2:10;
[X1,X2] = meshgrid(x1,x2);
F = mvnpdf([X1(:) X2(:)],mu,Sigma);
F = reshape(F,length(x2),length(x1));

%Values drawn from a normal distribution are 
%5-σ,4-σ and 3-σ awayfrom the mean
TL=1-erf([5 4 3]/sqrt(2));             
[C,h]=contour(x1,x2,F,TL,'ShowText','on');

However, I am not sure if it is possible to change the labels of this contours to 5-σ, 4-σ and 3-σ instead of numbers?

ASE
  • 1,702
  • 2
  • 21
  • 29