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 Center および File ExchangeGet 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