matthiasm@8: function h = draw_ellipse(x, c, outline_color, fill_color) matthiasm@8: % DRAW_ELLIPSE(x, c, outline_color, fill_color) matthiasm@8: % Draws ellipses at centers x with covariance matrix c. matthiasm@8: % x is a matrix of columns. c is a positive definite matrix. matthiasm@8: % outline_color and fill_color are optional. matthiasm@8: matthiasm@8: n = 40; % resolution matthiasm@8: radians = [0:(2*pi)/(n-1):2*pi]; matthiasm@8: unitC = [sin(radians); cos(radians)]; matthiasm@8: r = chol(c)'; matthiasm@8: matthiasm@8: if nargin < 3 matthiasm@8: outline_color = 'g'; matthiasm@8: end matthiasm@8: matthiasm@8: h = []; matthiasm@8: for i=1:cols(x) matthiasm@8: y = r*unitC + repmat(x(:, i), 1, n); matthiasm@8: if nargin < 4 matthiasm@8: h = [h line(y(1,:), y(2,:), 'Color', outline_color)]; matthiasm@8: else matthiasm@8: h = [h fill(y(1,:), y(2,:), fill_color, 'EdgeColor', outline_color)]; matthiasm@8: end matthiasm@8: end