Get ellipse function from datapoints
30 次查看(过去 30 天)
显示 更早的评论
Hi guys,
i want to get an ellipse function from given data.
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):
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.
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 个评论
采纳的回答
llueg
2019-7-24
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!