Fitting a curve to 3D data

조회 수: 4 (최근 30일)
Nikola Segedin
Nikola Segedin 2022년 3월 7일
댓글: Nikola Segedin 2022년 3월 7일
Hi people, I have a problem with fitting 3D data. I have a 3D matrix (99x386x384) and each dimension of the matrix represents x, y and z coordinates and value inside the matrix s value at a certain point value(x,y,z). Basically, I have a cluster of data points. I want to fit that data to the 3D curve/volume. Does anyone know how to do it?
  댓글 수: 10
Torsten
Torsten 2022년 3월 7일
I wonder why people always want analytical expressions, especially for something like a surface in 4d.
Use
sq = interp3(X,Y,Z,S,xq,yq,zq)
if you want a good approximation sq to your data in a query point (xq,yq,zq).
Bjorn Gustavsson
Bjorn Gustavsson 2022년 3월 7일
@Nikola Segedin if it looks like a Gaussian then tweak the Gaussian instead of jumping to polynomial fits. Perhaps something like this would be better:
Or some similar modifications...

댓글을 달려면 로그인하십시오.

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2022년 3월 7일
If you need to "get an idea to start" you can start from here:
function err = your_3D_error_fcn(pars,x,y,z,S,sigmaS,idx_is_OK_linear,fit_fcn)
S_model = fit_fcn(pars,x,y,z);
err = sum((S(idx_is_OK_linear)-S_model(idx_is_OK_linear)).^2./sigmaS(idx_is_OK_linear).^2)
end
This function you could use to find the best fiting parameters for a model-function using fminsearch:
fit_G3D = @(pars,x,y,z) pars(1)*exp(-(x-pars(2)).^2/pars(3)^2).* ...
exp(-(x-pars(4)).^2/pars(5)^2).* ...
exp(-(x-pars(6)).^2/pars(7)^2);
% Guessing parameters for an initial 3-D Gaussian with peak at 1 centred at
% [x,y,z] = [2 3 4] with widths in all directions equal to 1/2
pars0 = [1, 2,1/2,3,1/2,4,1/2];
pars_best = fminsearch(@(pars) your_3D_error_fcn(pars,x,y,z,S,sigmaS,idx_is_OK_linear,fit_G3D),pars0);
Here you'll have to provide the 3-D coordinates of x, y, z and s as well as an array with the linear indices to the good points and the standard-deviation of s (if that doesn't apply just remove it from the error-function). The error-function you'll have to adjust to something that suits your problem.
HTH
  댓글 수: 1
Nikola Segedin
Nikola Segedin 2022년 3월 7일
Thanks, I will try it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2010b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by