function h = plotgaussians(p1,mu1,sigma1,p2,mu2,sigma2,...
    xrange,yrange,linespecs,contourlines)
  % mu1,sigma2 and mu2,sigma2 each specify a 2-dim Gaussian
  % p1,p2 are their prior probabilities
  % Plots the contours for each of the two Gaussians (disregarding the priors),
  % as well as the decision boundary between them (taking into acount the priors).
  % All other arguments are optional: 
  % xrange=[fromx tox] specifies range of x values to plot (default -10 10)
  % yrange=[fromy toy] specifies range of y values to plot (default same as x)
  % linespecs is a cell array specifying line specifications for (in this order)
  %   the decision boundary, the first Gaussian, the second Gaussian
  % contourlines specifies the contour line values for the Gaussians
  if nargin<9
      linespecs = {'-k',':r','--b'};
  end
  if nargin<7
      xrange = [-10 10];
  end
  if nargin<8
      yrange = xrange;
  end
  if nargin<10
      contourlines = 5 ;
  end
  [x,y] = meshgrid(fillrange(xrange),fillrange(yrange));
  g1 = gaussian2d(x,y,mu1,sigma1);
  g2 = gaussian2d(x,y,mu2,sigma2);
  if length(contourlines)==1
      contourlines=0:(1.5/contourlines):1.5 ;
  end
  h = figure;
  hold;
  contour(x,y,g1*sqrt(det(sigma1)),contourlines,linespecs{2});
  contour(x,y,g2*sqrt(det(sigma2)),contourlines,linespecs{3});
  contour(x,y,p1*g1-p2*g2,[0 0],linespecs{1});

function filledrange = fillrange(range)
  filledrange = range(1):((range(2)-range(1))/100):range(2);