clear all; close all; clc; rng(0,'twister'); % For reproducibility % Generate data with an exponential trend x = (0:0.5:5)'; y = 2*exp(-0.2*x) + 0.1*randn(size(x)); [f,gof,output] = fit(x,y,'poly1'); f gof % Goodness-of-fit statistics, returned as the gof structure including the fields in this table. % Field % Value % sse % Sum of squares due to error % rsquare % R-squared (coefficient of determination) % dfe % Degrees of freedom in the error % adjrsquare % Degree-of-freedom adjusted coefficient of determination % rmse % Root mean squared error (standard error) output % Fitting algorithm information, returned as the output structure containing information associated with the fitting algorithm. % Fields depend on the algorithm. For example, the output structure for nonlinear least-squares algorithms includes the fields shown in this table. % % Field % Value % numobs % Number of observations (response values) % numparam % Number of unknown parameters (coefficients) to fit % residuals % Vector of raw residuals (observed values minus the fitted values) % Jacobian % Jacobian matrix % exitflag % Describes the exit condition of the algorithm. Positive flags indicate convergence, within tolerances. Zero flags indicate that the maximum number of function evaluations or iterations was exceeded. Negative flags indicate that the algorithm did not converge to a solution. %% iterations % Number of iterations %% funcCount % Number of function evaluations %% firstorderopt % Measure of first-order optimality (absolute maximum of gradient components) % algorithm % Fitting algorithm employed figure; hold on plot(x,y,'o'); plot(f)