-
Notifications
You must be signed in to change notification settings - Fork 0
/
1D_fit_example.m
40 lines (32 loc) · 1.06 KB
/
1D_fit_example.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
function [fitresult, gof] = createFit1(R, mins)
%CREATEFIT1(R,MINS)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : R
% Y Output: mins
% 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 10-May-2017 13:01:52
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( R, mins );
% Set up fittype and options.
ft = fittype( 'a*abs(reflection(e*236e6*2*pi,x-2000,b,1e-21,''L'',c,''C'',d));', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [-Inf 0 400 0 -Inf];
opts.StartPoint = [0.898151412909731 0 470 0.97 0.957506835434298];
opts.Upper = [Inf 500 600 10 Inf];
% 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, 'mins vs. R', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel R
ylabel mins
grid on