-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotEllipsis.m
More file actions
35 lines (28 loc) · 1.12 KB
/
Copy pathplotEllipsis.m
File metadata and controls
35 lines (28 loc) · 1.12 KB
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
function plotEllipsis(x_scores,y_scores,mycolor,alpha)
xsize = size(x_scores);
if xsize(1) < xsize(2)
x_scores = x_scores';
y_scores = y_scores';
end
STD = 1; %# standard deviations
conf = 2*normcdf(STD)-1; %# covers around 95% of population (for STD = 2)
scale = chi2inv(conf,2); %# inverse chi-squared with dof=#dimensions
%# substract mean
Mu = nanmean([x_scores y_scores]);
X0 = bsxfun(@minus, [x_scores y_scores], Mu);
%# eigen decomposition [sorted by eigen values]
Cov = nancov(X0) * scale;
[V D] = eig(Cov);
[D order] = sort(diag(D), 'descend');
D = diag(D);
V = V(:, order);
t = linspace(0,2*pi,100);
e = [cos(t) ; sin(t)]; %# unit circle
VV = V*sqrt(D); %# scale eigenvectors
e = bsxfun(@plus, VV*e, Mu'); %#' project circle back to orig space
tmpx = e(1,:);
tmpy = e(2,:);
% ltmp = patch(tmpx, tmpy, ones(size(tmpx)), ones(size(tmpx)));
% set(ltmp, 'FaceColor', mycolor, 'EdgeColor', 'none', 'FaceAlpha', alpha);
plot(tmpx,tmpy,'Color',mycolor,'LineWidth',2)
end