-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgmm1a.m
37 lines (33 loc) · 1.1 KB
/
gmm1a.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
function [fitresult, gof, coeff] = gmm1a(Tf,Tf2)
% Data for 'gmm1a' fit: input are column vector with
% Tf Input : fdam
% Tf2 Output: Tnm
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
% coeff : fit parameters
% Fit : fit vector(optional)
%% Fit: 'Skew Gaussian Distribution with 1 component'.
x = Tf2;
x = x(x>0);
y = Tf;
y = y((x>0));
[xData, yData] = prepareCurveData( x, y);
% Set up fittype and options.
ft = fittype( 'a1*exp(-((x-b1)/c1)^2).*(1+erf(d1*((x)-b1)/c1))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0 0 -10];
opts.MaxFunEvals = 6000;
opts.MaxIter = 4000;
opts.StartPoint = [0.01 0.06324 0.0975404049994095 0.278498218867048];
opts.Upper = [0.1 0.2 Inf 10];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Extract coefficients
c = coeffvalues(fitresult);
coeff = reshape(c,[],4);
% % Fit Vector
% FitFun = @(r) c(1).*exp(-((r-c(2))./c(3)).^2).*(1+erf(c(4).*(r-c(2))./c(3)));
% Fit = FitFun(x);
end