Fitting a plot with interpolation

조회 수: 6 (최근 30일)
HC98
HC98 2021년 6월 16일
댓글: laurent jalabert 2022년 6월 17일
I need to interpolate some data involving a logarithm using the fit function but I'm not sure how to interpolate in matlab. Generally speaking, how does one interpolate data in MATLAB?

답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 16일
interp1() for 1D cases, interp2() for 2D cases
However, it does not sound to be as if you want to use either. It looks to me as if you want to use the Curve Fitting Toolbox fittype() and fit() functions. Then you want to evaluate the fitted model at a particular location, which you can do by using the returned fit object as if it were a function.
F = fittype('poly2')
F =
Linear model Poly2: F(p1,p2,p3,x) = p1*x^2 + p2*x + p3
p = fit((1:5).', rand(5,1), F)
p =
Linear model Poly2: p(x) = p1*x^2 + p2*x + p3 Coefficients (with 95% confidence bounds): p1 = -0.01913 (-0.5426, 0.5044) p2 = 0.05751 (-3.144, 3.259) p3 = 0.4766 (-3.725, 4.678)
p(7)
ans = -0.0583
Except that you would be constructing a different fittype() object, and using real data instead of the fake data I used here.
  댓글 수: 4
SALAH ALRABEEI
SALAH ALRABEEI 2021년 6월 16일
Thank you, this resource is really useful.
laurent jalabert
laurent jalabert 2022년 6월 17일
how can I write the syntax of a nonlinear regression fitting model involving an interp1 that contains a fitting parameter ?
table_theory is a table of X and Y vector (length ~ 300)
table_exper is a table of x and y experimental data (length ~50)
RP = interp1(table_theory,500)
modelR = @(x )beta * RP(alpha * x)
alpha and beta the fitting parameters
h_mdl = fitnlm(table_exper,modelR,beta,'CoefficientNames',{'apha';'beta'});
I would like to take table_exper, then find the best coefficient alpha (on x-axis) and beta (on y-axis) so that the resulting y=beta * RP(alpha * x) will be the closest to the table_theory.

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

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by