annotate toolboxes/FullBNT-1.0.7/KPMtools/plotgauss2d_old.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function h=plotgauss2d_old(mu, Sigma, plot_cross)
wolffd@0 2 % PLOTGAUSS2D Plot a 2D Gaussian as an ellipse with optional cross hairs
wolffd@0 3 % h=plotgauss2(mu, Sigma)
wolffd@0 4 %
wolffd@0 5 % h=plotgauss2(mu, Sigma, 1) also plots the major and minor axes
wolffd@0 6 %
wolffd@0 7 % Example
wolffd@0 8 % clf; S=[2 1; 1 2]; plotgauss2d([0;0], S, 1); axis equal
wolffd@0 9
wolffd@0 10 if nargin < 3, plot_cross = 0; end
wolffd@0 11 [V,D]=eig(Sigma);
wolffd@0 12 lam1 = D(1,1);
wolffd@0 13 lam2 = D(2,2);
wolffd@0 14 v1 = V(:,1);
wolffd@0 15 v2 = V(:,2);
wolffd@0 16 %assert(approxeq(v1' * v2, 0))
wolffd@0 17 if v1(1)==0
wolffd@0 18 theta = 0; % horizontal
wolffd@0 19 else
wolffd@0 20 theta = atan(v1(2)/v1(1));
wolffd@0 21 end
wolffd@0 22 a = sqrt(lam1);
wolffd@0 23 b = sqrt(lam2);
wolffd@0 24 h=plot_ellipse(mu(1), mu(2), theta, a,b);
wolffd@0 25
wolffd@0 26 if plot_cross
wolffd@0 27 mu = mu(:);
wolffd@0 28 held = ishold;
wolffd@0 29 hold on
wolffd@0 30 minor1 = mu-a*v1; minor2 = mu+a*v1;
wolffd@0 31 hminor = line([minor1(1) minor2(1)], [minor1(2) minor2(2)]);
wolffd@0 32
wolffd@0 33 major1 = mu-b*v2; major2 = mu+b*v2;
wolffd@0 34 hmajor = line([major1(1) major2(1)], [major1(2) major2(2)]);
wolffd@0 35 %set(hmajor,'color','r')
wolffd@0 36 if ~held
wolffd@0 37 hold off
wolffd@0 38 end
wolffd@0 39 end
wolffd@0 40