function [fitresult, gof] = createFit(phiEq, phiM,phiS,varargin) %CREATEFIT(PHIEQ,PHIM) % Create a fit. % % Data for 'untitled fit 1' fit: % X Input : phiEq % Y Output: phiM % Output: % fitresult : a fit object representing the fit. % gof : structure with goodness-of fit info. % % See also FIT, CFIT, SFIT. % Auto-generated by MATLAB on 26-May-2020 22:41:37 %% Fit: 'untitled fit 1'. [xData, yData, weights] = prepareCurveData( phiEq, phiM, phiS); if nargin == 6 onset = [varargin{1} varargin{1} varargin{1}]; aIn = [varargin{2} varargin{2} varargin{2}]; dIn = [varargin{3} varargin{3} varargin{3}]; else onset = [0 0.46 1]; aIn = [0 1 1000]; dIn = [0 0.2 1]; end % Set up fittype and options. ft = fittype( '(c + f*(x-b))*(1 + d*log(1 + exp(a*(x-b))))', 'independent', 'x', 'dependent', 'y' ); opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); opts.DiffMaxChange = 0.01; opts.Display = 'Off'; opts.Lower = [aIn(1) onset(1) 0 dIn(2) 0]; opts.MaxFunEvals = 6000; opts.MaxIter = 4000; opts.Robust = 'Bisquare'; opts.StartPoint = [aIn(2) onset(2) 1 dIn(2) 0.642802630335228]; opts.TolFun = 1e-08; opts.TolX = 1e-08; opts.Upper = [aIn(3) onset(3) 1 dIn(3) 1]; opts.Weights = weights; % Fit model to data. [fitresult, gof] = fit( xData, yData, ft, opts ); % Plot fit with data. % figure( 'Name', 'untitled fit 1' ); % h = plot( fitresult, xData, yData ); % legend( h, 'phiM vs. phiEq', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' ); % % Label axes % xlabel( 'phiEq', 'Interpreter', 'none' ); % ylabel( 'phiM', 'Interpreter', 'none' ); % grid on