Daniel@0: function h=plotgauss2d_old(mu, Sigma, plot_cross) Daniel@0: % PLOTGAUSS2D Plot a 2D Gaussian as an ellipse with optional cross hairs Daniel@0: % h=plotgauss2(mu, Sigma) Daniel@0: % Daniel@0: % h=plotgauss2(mu, Sigma, 1) also plots the major and minor axes Daniel@0: % Daniel@0: % Example Daniel@0: % clf; S=[2 1; 1 2]; plotgauss2d([0;0], S, 1); axis equal Daniel@0: Daniel@0: if nargin < 3, plot_cross = 0; end Daniel@0: [V,D]=eig(Sigma); Daniel@0: lam1 = D(1,1); Daniel@0: lam2 = D(2,2); Daniel@0: v1 = V(:,1); Daniel@0: v2 = V(:,2); Daniel@0: %assert(approxeq(v1' * v2, 0)) Daniel@0: if v1(1)==0 Daniel@0: theta = 0; % horizontal Daniel@0: else Daniel@0: theta = atan(v1(2)/v1(1)); Daniel@0: end Daniel@0: a = sqrt(lam1); Daniel@0: b = sqrt(lam2); Daniel@0: h=plot_ellipse(mu(1), mu(2), theta, a,b); Daniel@0: Daniel@0: if plot_cross Daniel@0: mu = mu(:); Daniel@0: held = ishold; Daniel@0: hold on Daniel@0: minor1 = mu-a*v1; minor2 = mu+a*v1; Daniel@0: hminor = line([minor1(1) minor2(1)], [minor1(2) minor2(2)]); Daniel@0: Daniel@0: major1 = mu-b*v2; major2 = mu+b*v2; Daniel@0: hmajor = line([major1(1) major2(1)], [major1(2) major2(2)]); Daniel@0: %set(hmajor,'color','r') Daniel@0: if ~held Daniel@0: hold off Daniel@0: end Daniel@0: end Daniel@0: