MATLAB: Export residuals from curve fitting

curve fittingCurve Fitting ToolboxMATLABresiduals

Hi,
I am using the curve fitting toolbox on MATLAB_R2019a to create a (linear least square fit) by creating a (Polynomial fit with 1 degree).
I would like to export the residuals values to an array. I know I can acheive that manually from Fit >> Save to work space >> output.
But I have a loop around 1000 file so I would like to export residuals individually for each fit.
Any help is apprciated.

Best Answer

Instead of using cftool, use the fit() command,
[fitobject,gof,output] = fit(x,y,'poly1','Weights', w);
residuals=output.residuals;