Toolboxes
Curve Fitting Toolbox → scipy.optimize + numpy.polyfit
Fit curves to data. scipy.optimize.curve_fit covers 95% of MATLAB's fit() usage; polyfit/polyval match directly. For interactive fitting, the MATLAB `cftool` GUI has no Python equivalent — but a Jupyter notebook with matplotlib widgets comes close.
Install
pip install scipy| MATLAB | Python | Note |
|---|---|---|
| fit(x, y, 'poly2') | np.polyfit(x, y, 2) | Polynomial order N → degree N |
| fit(x, y, 'poly1') | np.polyfit(x, y, 1) | Linear fit |
| polyfit(x, y, n) | np.polyfit(x, y, n) | |
| polyval(p, x) | np.polyval(p, x) | |
| fit(x, y, 'exp1') | from scipy.optimize import curve_fit\nfit, cov = curve_fit(lambda x, a, b: a*np.exp(b*x), x, y) | Exponential fit via curve_fit |
| fit(x, y, customModel) | scipy.optimize.curve_fit(model, x, y) | Pass any callable as the model |
| goodnessOfFit | from sklearn.metrics import r2_score\nr2_score(y, y_fit) | R² via sklearn, or compute manually |
| confint(fitobject) | 95% CI from sqrt(diag(cov)) # from curve_fit covariance | No direct function — compute from covariance matrix |
| smooth(y, 'sgolay') | scipy.signal.savgol_filter(y, window, order) | Savitzky–Golay |
| interp1(x, y, xi) | scipy.interpolate.interp1d(x, y)(xi) | Default 'linear'; kind='cubic' for spline |
| interp2(X, Y, Z, xi, yi) | scipy.interpolate.interp2d(X, Y, Z)(xi, yi) | Or RegularGridInterpolator for newer scipy |
| spline(x, y, xi) | scipy.interpolate.CubicSpline(x, y)(xi) | |
| csaps(x, y, p, xi) | scipy.interpolate.UnivariateSpline(x, y, s=...) | Smoothing spline |
The converter automatically detects Curve Fitting functions and adds the correct imports.
Try the converter