Best matlab curve fitting functions?

I have the following set of data:
x=[0 .1579 .3158 .4737 .6316 .7895 .9474 1.1053 1.2632 1.4211 1.5789 1.7368 1.8947 2.0526 2.2105 2.3684 2.5263 2.6842 2.8421 3]';
fx=[-.3637 .3164 -1.1263 -1.0672 .1076 1.8249 -.1899 1.3484 1.2583 3.2179 1.7378 3.6954 5.1611 6.7646 8.3733 8.1898 7.9968 10.2402 11.5248 16.6505]';
I have to fit a curve to this data, without using matlabs curve fitting toolbox. What are the best built in matlab functions to fit data like this?

 採用された回答

Star Strider
Star Strider 2014 年 11 月 21 日

0 投票

There are three other functions you can use to fit nonlinear data: nlinfit (Statistics Toolbox), lsqcurvefit (Optimization Toolbox), and fminsearch (built-in MATLAB function).
Do you have a model you want to fit? (It looks like a noisy exponential function, but the process that created it dictates the model you fit to it.)

7 件のコメント

the cyclist
the cyclist 2014 年 11 月 21 日
... or polyfit if you want to assume that fx is a polynomial function of x.
Andrew
Andrew 2014 年 11 月 21 日
No, I just have the data provided. I've used polyfit, interp1, and regress already.
Image Analyst
Image Analyst 2014 年 11 月 21 日
What do you want once you're all done: a formula (equation), or a smoothed or interpolated set of numbers? If you want numbers, you can use Savitzky-Golay (Signal Processing Toolbox) or conv() (base MATLAB) - either will smooth the data. If you want a formula you can use polyfit to get coefficients, and then use polyval to get actual numbers.
Andrew
Andrew 2014 年 11 月 21 日
I want a curve that somewhat accurately fits the curve. It doesn't have to be exact, but the closer the fit the better. I just can't use the curve fitting toolbox.
Star Strider
Star Strider 2014 年 11 月 21 日
This produces an acceptable fit:
x=[0 .1579 .3158 .4737 .6316 .7895 .9474 1.1053 1.2632 1.4211 1.5789 1.7368 1.8947 2.0526 2.2105 2.3684 2.5263 2.6842 2.8421 3]';
fx=[-.3637 .3164 -1.1263 -1.0672 .1076 1.8249 -.1899 1.3484 1.2583 3.2179 1.7378 3.6954 5.1611 6.7646 8.3733 8.1898 7.9968 10.2402 11.5248 16.6505]';
fitfn = @(b,x) b(1).*exp(b(2).*x)+b(3);
B0 = rand(3,1);
B = nlinfit(x, fx, fitfn, B0);
figure(1)
plot(x, fx, 'pb')
hold on
plot(x, fitfn(B,x), '-r')
hold off
grid
The ‘B’ vector are the estimated parameters. If you need statistics on the parameters or the fit, you can ask nlinfit for the appropriate outputs and use nlparci and nlpredci. You can also use fitnlm with ‘fitfn’ and get even more statistics as part of the process without having to do anything else.
Andrew
Andrew 2014 年 11 月 21 日
That's what I was looking for. Thanks a lot
Star Strider
Star Strider 2014 年 11 月 21 日
編集済み: Star Strider 2014 年 11 月 21 日
My pleasure!
The sincerest expression of appreciation here on MATLAB Answers is to Accept the answer that most closely solves your problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

タグ

質問済み:

2014 年 11 月 21 日

編集済み:

2014 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by