annotate _FullBNT/KPMtools/plotgauss2d_old.m @ 9:4ea6619cb3f5 tip

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