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

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function h=plotgauss2d_old(mu, Sigma, plot_cross)
Daniel@0 2 % PLOTGAUSS2D Plot a 2D Gaussian as an ellipse with optional cross hairs
Daniel@0 3 % h=plotgauss2(mu, Sigma)
Daniel@0 4 %
Daniel@0 5 % h=plotgauss2(mu, Sigma, 1) also plots the major and minor axes
Daniel@0 6 %
Daniel@0 7 % Example
Daniel@0 8 % clf; S=[2 1; 1 2]; plotgauss2d([0;0], S, 1); axis equal
Daniel@0 9
Daniel@0 10 if nargin < 3, plot_cross = 0; end
Daniel@0 11 [V,D]=eig(Sigma);
Daniel@0 12 lam1 = D(1,1);
Daniel@0 13 lam2 = D(2,2);
Daniel@0 14 v1 = V(:,1);
Daniel@0 15 v2 = V(:,2);
Daniel@0 16 %assert(approxeq(v1' * v2, 0))
Daniel@0 17 if v1(1)==0
Daniel@0 18 theta = 0; % horizontal
Daniel@0 19 else
Daniel@0 20 theta = atan(v1(2)/v1(1));
Daniel@0 21 end
Daniel@0 22 a = sqrt(lam1);
Daniel@0 23 b = sqrt(lam2);
Daniel@0 24 h=plot_ellipse(mu(1), mu(2), theta, a,b);
Daniel@0 25
Daniel@0 26 if plot_cross
Daniel@0 27 mu = mu(:);
Daniel@0 28 held = ishold;
Daniel@0 29 hold on
Daniel@0 30 minor1 = mu-a*v1; minor2 = mu+a*v1;
Daniel@0 31 hminor = line([minor1(1) minor2(1)], [minor1(2) minor2(2)]);
Daniel@0 32
Daniel@0 33 major1 = mu-b*v2; major2 = mu+b*v2;
Daniel@0 34 hmajor = line([major1(1) major2(1)], [major1(2) major2(2)]);
Daniel@0 35 %set(hmajor,'color','r')
Daniel@0 36 if ~held
Daniel@0 37 hold off
Daniel@0 38 end
Daniel@0 39 end
Daniel@0 40