How to fit data to my customized form automatically?

I have quite a few sets of data and I want to fit them to y=a-b*x^3. I know that I could use cftool and do it manually for each data set. But it is really tedious. Is it a better way to do it? Thanks a lot.

 采纳的回答

Since you're already using Curve Fitting Toolbox, use the underlying functions: fitttype and fit.
Example:
f = fittype('a-b*x^3', 'independent', 'x', 'coefficients', {'a', 'b'});
fitobj = fit(rand(10,1), rand(10,1), f)
Alternatively, you can generate MATLAB code from cftool.

更多回答(1 个)

doc polyfit

3 个评论

I thought about polyfit. But I don't want to fit y=p3*x^3+p2*x^2+p1*x+p0. Instead, I want p2 and p1 to be 0. I don't see that I could specify this option in using polyfit.
you get the p values from polyfit
I want to fix p1 and p2 to be 0. I need y=p3*x^3+p0.

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by