Fitting a plot with interpolation

5 views (last 30 days)
HC98 on 16 Jun 2021
Commented: SALAH ALRABEEI on 16 Jun 2021
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?

Answers (1)

Walter Roberson
Walter Roberson on 16 Jun 2021
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)
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.
SALAH ALRABEEI on 16 Jun 2021
Thank you, this resource is really useful.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!