Get ellipse function from datapoints
11 views (last 30 days)
Show older comments
Hi guys,
i want to get an ellipse function from given data.
![001.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231080/001.png)
In this data, outliers are removed. Now I want to get the function of an approximate ellipse, which is around the points. It is clear, that there will be some inaccuracy.
The final ellipse should look (just as my initial guess):
![002.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231081/002.png)
My former approaches was to use rmoutliers to delete the inner points, but there isnt any option to circular fit points, so a "window" will be the result.
![003.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/231082/003.png)
With this (purple) points, i ran some ellipse fit functions from matlab file exchange.
All the results werent satisfying.
How can I (1.) remove the inner points of the data, to get an ellipse (and not this x-y-window) and (2.) how can I detect the ellipse function from the data?
0 Comments
Accepted Answer
llueg
on 24 Jul 2019
You can use Eigen decomposition to come up with the parameters for the ellipse. You then scale the size of the ellipse based on how many standard deviations you want to include. The components of the ellipse are computed from the eigen decomposition of your data matrix. I pretty much copied the code below from here.
%for demonstration, I generated some data: 100 points in 2D
X = normrnd(0,2,[100 2]);
%the mean should be at zero
Mu = mean(X);
X0 = bsxfun(@minus, X, Mu);
%scale the size of the ellipse based on standard deviatioon
STD = 2;
%covers around 95% of population
conf = 2*normcdf(STD)-1;
%inverse chi-squared with dof=dimensions
scale = chi2inv(conf,2);
Cov = cov(X0) * scale;
% eigen decomposition [sorted by eigen values]
[V, D] = eig( Cov );
[D, order] = sort(diag(D), 'descend');
D = diag(D);
V = V(:, order);
t = linspace(0,2*pi,100);
% unit circle
e = [cos(t) ; sin(t)];
% scale eigenvectors
VV = V*sqrt(D);
% project circle back to orig space
e = bsxfun(@plus, VV*e, Mu');
% plot cov and major/minor axes
figure(1)
plot(e(1,:), e(2,:), 'Color','b');
hold on
scatter(X(:,1),X(:,2))
hold off
3 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!