Approximation coefficients differencies when function fit and Fitting Curve are used

1 view (last 30 days)
There is a problem of approximation when i use function fit. When i use Fitting Curve i really get good approximation coefficients, because start point parametres are given by program when i choose x and y vectors before fit. When i use fit function start points are random. I can not indicate start points by mysefl and i don't know how can i get the same approximation coefficients when i use function fit and when i use Fitting Curve.
  4 Comments
UserAlex
UserAlex on 25 Oct 2019
And function fit use random start points if i did not enter them, cftool interface use their coefficients
UserAlex
UserAlex on 25 Oct 2019
function [fitresult, gof] = createFit(NOISEP, SetNumberP)
%CREATEFIT(NOISEP,SETNUMBERP)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : NOISEP
% Y Output: SetNumberP
% 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 25-Oct-2019 20:55:17
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( NOISEP, SetNumberP );
% Set up fittype and options.
ft = fittype( 'gauss2' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0 -Inf -Inf 0];
opts.StartPoint = [1 0.987772030980821 0.0127833870316064 0.789954196169235 0.967363517944027 0.0205518543316703];
% 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, 'SetNumberP vs. NOISEP', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel NOISEP
ylabel SetNumberP
grid on

Sign in to comment.

Answers (1)

Matt J
Matt J on 25 Oct 2019
Edited: Matt J on 25 Oct 2019
What is "Fitting Curve"? Do you mean the Curve Fitting app? Why do you think the fit function uses different starting points than the app? It shouldn't. It is using the fit() function internally, just as you are attempting to do. You can use the drop down menu option File>>Generate Code in the app to see how it invoked the fit() command to do the fit.
  4 Comments
UserAlex
UserAlex on 25 Oct 2019
function [fitresult, gof] = createFit(NOISEP, SetNumberP)
%CREATEFIT(NOISEP,SETNUMBERP)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : NOISEP
% Y Output: SetNumberP
% 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 25-Oct-2019 20:55:17
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( NOISEP, SetNumberP );
% Set up fittype and options.
ft = fittype( 'gauss2' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf 0 -Inf -Inf 0];
opts.StartPoint = [1 0.987772030980821 0.0127833870316064 0.789954196169235 0.967363517944027 0.0205518543316703];
% 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, 'SetNumberP vs. NOISEP', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel NOISEP
ylabel SetNumberP
grid on
Matt J
Matt J on 25 Oct 2019
Edited: Matt J on 25 Oct 2019
Ah well. That's not convenient. I suggest you post your data in a .mat file, so that we can get an idea of what it looks like and how to fit it.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!