Curve (Line) Fitting in 3D
Show older comments
Hi, I've noticed John D'Errico answering a few of these questions but the polyfitn doesn't seem at first trial to do what I want. But I have some data in x,y,z coordinates. See attached for coordinates. I have manually selected x,y from images based on z = [0:2:100]. However I'm not sure how to fit a curve to this in 3D in order to remove error due to manual selection.
2 Comments
Star Strider
on 27 Apr 2017
What function do you want to fit to your data?
Alec Day
on 1 May 2017
Accepted Answer
More Answers (1)
Steffen B. Petersen
on 16 Dec 2017
0 votes
I read your question such that you have a large number of points in 3D (x,y,z), and you want to fit a line through these points.
You should principal component analysis : First you 'whiten' your data by subtracting the mean of you data from each data point. Let us call your mean 'myaverage' - this is point in 3D space at the center of your data. Let us call the whitened data (X,Y,Z)
(X,Y,Z)=(x,y,z)-myaverage
Second you use pca to extract the coefficients - in this case a 3x3 matrix where the first column is the vector that has the largest varians over your dataset.
[coefficient]=pca(X,Y,Z);
You can now draw a line through your datapoints using
mypoint=myaverage+t*coefficient(:,1)
by varying the parameter t you find the points for your fitted line. From this point off you may want to compute the RMS deviation - but that probably is not your problem.
Regards
Steffen
1 Comment
Sarvesh Singh
on 15 Feb 2018
Edited: Sarvesh Singh
on 15 Feb 2018
Hi Steffen,
I'm trying to implement this. Can you please elaborate what this parameter 't' is and what should be its typical value for the best fit. Also is it possible to fit any other curve instead of line using this method?
Regards,
Sarvesh
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
