function[obsah_95elipsa]=error_ellipse(horizontalni,vertikalni_bez_mrk)
obsah95_elipsa=[];
y1=horizontalni;
y2=vertikalni_bez_mrk;
% this file was donloaded from:
% http://www.visiondummy.com/2014/04/draw-error-ellipse-representing-covariance-matrix/

% Calculate the eigenvectors and eigenvalues
covariance = cov(y1,y2);
[eigenvec, eigenval ] = eig(covariance);

% Get the index of the largest eigenvector
[largest_eigenvec_ind_c, r] = find(eigenval == max(max(eigenval)));
largest_eigenvec = eigenvec(:, largest_eigenvec_ind_c);

% Get the largest eigenvalue
largest_eigenval = max(max(eigenval));

% Get the smallest eigenvector and eigenvalue
if(largest_eigenvec_ind_c == 1)
    smallest_eigenval = max(eigenval(:,2));
    smallest_eigenvec = eigenvec(:,2);
else
    smallest_eigenval = max(eigenval(:,1));
    smallest_eigenvec = eigenvec(1,:);
end

% 
chisquare_val = 2.4477;
a=chisquare_val*sqrt(largest_eigenval);
b=chisquare_val*sqrt(smallest_eigenval);
obsah_95elipsa = a*b*pi;
end


