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