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