-
Notifications
You must be signed in to change notification settings - Fork 30
/
ellipse.m
36 lines (31 loc) · 882 Bytes
/
ellipse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function [o1,o2]=ellipse(mu,cmat,varargin)
%ELLIPSE Draws a probability contour ellipse
% ellipse(mu,cmat) draws an ellipse centered at mu and with
% covariance matrix cmat.
% h = ellipse(...) plots and returns handle to the ellipse line
% [x,y] = ellipse(...) returns ellipse points (no plot)
% use chiqf(0.9,2)*cmat to get 90% Gaussian probability region
% example:
% plot(x(:,1),x(:,2),'.'); % plot data points
% hold on; ellipse(xmean, chiqf(0.9,2)*xcov); hold off
% Marko Laine <[email protected]>
% $Revision: 1.7 $ $Date: 2012/09/27 11:47:35 $
if size(cmat)~=[2 2]
error('covmat must be 2x2');
end
if cmat~=cmat'
error('covmat must be symmetric');
end
t = linspace(0,2*pi)';
R = chol(cmat);
x = mu(1) + R(1,1).*cos(t);
y = mu(2) + R(1,2).*cos(t) + R(2,2).*sin(t);
if nargout<2
hh = plot(x,y,varargin{:});
else
o1 = x;
o2 = y;
end
if nargout==1
o1=hh;
end