-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateFit.m
More file actions
40 lines (32 loc) · 1.02 KB
/
createFit.m
File metadata and controls
40 lines (32 loc) · 1.02 KB
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] = createFit(x, y2)
%CREATEFIT(X,Y2)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : x
% Y Output: y2
% 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 17-Apr-2017 09:13:49
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( x, y2 );
% Set up fittype and options.
ft = fittype( 'a*abs(reflection(x*2*pi,Rs,Ro,1e-10,''L'',L,''C'',C))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0.9 500 0 0 -Inf];
opts.StartPoint = [0.9429 820 600 50000 0.0242];
opts.Upper = [1 825 1000 Inf 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, 'y2 vs. x', 'untitled fit 1', 'Location', 'NorthEast' );
% Label axes
xlabel x
ylabel y2
grid on