-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingexpfit.m
53 lines (47 loc) · 1.78 KB
/
singexpfit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [fitresult, gof] = singexpfit(corrxax, concrosscorr)
%CREATEFIT(CORRXAX,CONCROSSCORR)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input: corrxax
% Y Output: concrosscorr
% 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 12-Jan-2023 23:25:55
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( corrxax, concrosscorr );
assignin("base","fitxData",xData) % writes fitdata to workspace in case the fit function crashes
assignin("base","fityData",yData)
ft = fittype( 'a*exp(-x/b)+c', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Algorithm = 'Levenberg-Marquardt';
opts.MaxFunEvals = 6000;
opts.MaxIter = 4000;
opts.Display = 'Off';
opts.Robust = 'Bisquare';
%opts.StartPoint = [-0.03059 0.1616 0.107];
opts.StartPoint = [0.754686681982361 0.276025076998578 0.679702676853675];
% Fit model to data.
try
opts.StartPoint = [-0.03059 0.1616 0.107];
[fitresult, gof] = fit( xData, yData, ft, opts );
catch
try
opts.StartPoint = [0.754686681982361 0.276025076998578 0.679702676853675];
[fitresult, gof] = fit( xData, yData, ft, opts );
catch
opts.StartPoint = [0.754686681982361 0.276025076998578 0.679702676853675]; %insert other values to try fit with
[fitresult, gof] = fit( xData, yData, ft, opts );
end
end
% Plot fit with data.
% figure( 'Name', 'untitled fit 1' );
% h = plot( fitresult, xData, yData );
% legend( h, 'concrosscorr vs. corrxax', 'untitled fit 1', 'Location', 'NorthEast', 'Interpreter', 'none' );
% % Label axes
% xlabel( 'corrxax', 'Interpreter', 'none' );
% ylabel( 'concrosscorr', 'Interpreter', 'none' );
% grid on