Issue with Curve Fitting tooland code

1 次查看(过去 30 天)
dear all I have generated a code from CFT and have personalised so to be able to import data from excel and add starting points for a customised equation. The code looks as follows
% CREATEFIT(RR ,QT ) % Create a 3P exponential fit. % % Data for 'untitled fit 1' fit: % X Input : RR % Y Output: QT % Output: % fitresult : a fit object representing the fit. % gof : structure with goodness-of fit info.
[filename file_path]= uigetfile ({'*.xls';'*.xlsx'},'Select an Excel File'); x = xlsread(strcat(file_path, filename), 'C31:C1048576'); y = xlsread(strcat(file_path, filename), 'D31:D1048576');
x(isnan(x)) = []; y(isnan(y))=[];
%% Fit: 'untitled fit 1'. [xData, yData] = prepareCurveData( x, y );
% Set up fittype and options. ft = fittype( 'a*exp(-b*x)+c', 'independent', 'x', 'dependent', 'y' ); opts = fitoptions( 'Method', 'NonlinearLeastSquares' ); opts.Display = 'Off'; opts.StartPoint = [-min(y) 0.01 max(y)];
% Fit model to data. [fitresult, gof] = fit( xData, yData, ft, opts );
a = fitresult.a; b = fitresult.b; c = fitresult.c;
a = num2str(a); b = num2str(b); c = num2str(c);
eq = ['y = ' a ' *exp( ' b '*RR )+' c]; dNo = filename(1:15);
% Plot fit with data. figure( 'Name', dNo); h = plot( fitresult, xData, yData ); legend( h,dNo, eq, 'Location', 'SouthEast' ); % Label axes xlabel RR ylabel QT grid on
% create a tiff file of the figure # % using the dNo as file name
outName = strcat(dNo, '.tiff'); saveas(gcf, outName);
Proble is that when I use the tool with the same data and same initial points, the results I am obtaining are different compared to those I get if I am using the code. I can't find the problem and not sure which of the two results I get is the correct one. Any suggestion/advice? I am using Matlab 2015a. Thank you Marcello

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by