% function [fitresult, gof] = createFit(theta, M1) % %CREATEFIT(THETA,M1) % % Create a fit. % % % % Data for 'untitled fit 1' fit: % % X Input : theta % % Y Output: M1 % % Output: % % fitresult : a fit object representing the fit. % % gof : structure with goodness-of fit info. % % see with FIT, CFIT, SFIT. % %% Fit: 'untitled fit 1'. % [xData, yData] = prepareCurveData( theta, M1 ); % % % Set up fittype and options. % ft = fittype( 'k*sin(x)*((1-exp(-200/t1))./(1-exp(-200/t1)*cos(x)))', 'independent', 'x', 'dependent', 'y' ); % opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); % opts.Display = 'Off'; % opts.Lower = [-Inf 0]; % opts.StartPoint = [1000 1000]; % opts.Upper = [Inf 3000]; % % % 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, 'M1 vs. theta', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' ); % % Label axes % xlabel( 'theta', 'Interpreter', 'none' ); % ylabel( 'M1', 'Interpreter', 'none' ); % grid on % % r1*x+b %% % function [fitresult, gof] = createFit(theta, M3) % %CREATEFIT(THETA,M3) % % Create a fit. % % % % Data for 'untitled fit 1' fit: % % X Input : theta % % Y Output: M3 % % Output: % % fitresult : a fit object representing the fit. % % gof : structure with goodness-of fit info. % %% Fit: 'untitled fit 1'. % [xData, yData] = prepareCurveData( theta, M3 ); % % % Set up fittype and options. % ft = fittype( 'k*sin(x)*((1-exp(-200/t1))./(1-exp(-200/t1)*cos(x)))', 'independent', 'x', 'dependent', 'y' ); % opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); % opts.Display = 'Off'; % opts.StartPoint = [1000 1000]; % % % 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, 'M3 vs. theta', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' ); % % Label axes % xlabel( 'theta', 'Interpreter', 'none' ); % ylabel( 'M3', 'Interpreter', 'none' ); % grid on %% function [fitresult, gof] = createFit(theta, M8) %CREATEFIT(THETA,M8) % Create a fit. % % Data for 'untitled fit 1' fit: % X Input : theta % Y Output: M8 % Output: % fitresult : a fit object representing the fit. % gof : structure with goodness-of fit info. %% Fit: 'untitled fit 1'. [xData, yData] = prepareCurveData( theta, M8 ); % Set up fittype and options. ft = fittype( 'k*sin(x)*((1-exp(-200/t1))./(1-exp(-200/t1)*cos(x)))', 'independent', 'x', 'dependent', 'y' ); opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); opts.Display = 'Off'; opts.Lower = [-Inf 0]; opts.StartPoint = [1000 100]; % 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, 'M8 vs. theta', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' ); % Label axes xlabel( 'theta', 'Interpreter', 'none' ); ylabel( 'M8', 'Interpreter', 'none' ); grid on