function [fitresult, gof] = createFit(SQRT_tsat, SDTD) %CREATEFIT(SQRT_TSAT,SDTD) % Create a fit. % % Data for 'SDTD_fit' fit: % X Input : SQRT_tsat % Y Output: SDTD % 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 06-May-2020 16:15:54 % export data fname = '/Users/jcmunoz/Documents/UEA/test_SDTD_fit_Matlab.xlsx'; data = readmatrix(fname); SQRT_tsat = data(:,1); SDTD = data(:,2); scatter(SQRT_tsat,SDTD); %% Fit: 'untitled fit 1'. [xData, yData] = prepareCurveData( SQRT_tsat, SDTD ); % Set up fittype and options. ft = fittype( 'C*erfc(r/(sqrt(4*D*x))-b)', 'independent', 'x', 'dependent', 'y' ); opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); opts.Display = 'Off'; opts.Lower = [-Inf 0 1 0.2]; opts.StartPoint = [1 0.00012 1 0.2]; opts.Upper = [Inf 0.1 1 0.2]; % Fit model to data. [fitresult, gof] = fit( xData, yData, ft, opts ); % Plot fit with data. figure( 'Name', 'SDTD_fit' ); h = plot( fitresult, xData, yData ); legend( h, 'SDTD vs. SQRT_tsat', 'SDTD_fit', 'Location', 'NorthEast', 'Interpreter', 'none' ); % Label axes xlabel( 'SQRT_tsat', 'Interpreter', 'none' ); ylabel( 'SDTD', 'Interpreter', 'none' ); grid on