-
Notifications
You must be signed in to change notification settings - Fork 0
/
2D_fit_example.m
44 lines (36 loc) · 1.11 KB
/
2D_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
39
40
41
42
function [fitresult, gof] = createFit1(x, R, z)
%CREATEFIT1(X,R,Z)
% Create a fit.
%
% Data for 'untitled fit 1' fit:
% X Input : x
% Y Input : R
% Z Output: z
% 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 11-May-2017 11:07:41
%% Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( x, R, z );
% Set up fittype and options.
ft = fittype( 'a.*abs(reflection(x.*1e6.*2.*pi,y-1000,b,1e-21,''L'',c,''C'',d))', 'independent', {'x', 'y'}, 'dependent', 'z' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.Lower = [0 0 0 0];
opts.Robust = 'off';
opts.StartPoint = [0.6 0 470 0.97];
opts.Upper = [1 0 500 1];
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, opts );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'z vs. x, R', 'Location', 'NorthEast' );
% Label axes
xlabel x
ylabel R
zlabel z
grid on
view( -62.7, -23.6 );