-
Notifications
You must be signed in to change notification settings - Fork 0
/
gauss_cftikkevigtig.m
41 lines (33 loc) · 1.15 KB
/
gauss_cftikkevigtig.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
function [fitresult, gof] = gauss_cft(X, Y, submatrix_red)
%CREATEFIT(X,Y,SUBMATRIX_RED)
% Create a fit.
%
% Data for 'gauss_2d' fit:
% X Input : X
% Y Input : Y
% Z Output: submatrix_red
% 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 26-Nov-2018 13:57:40
%% Fit: 'gauss_2d'.
[xData, yData, zData] = prepareSurfaceData( X, Y, submatrix_red );
% Set up fittype and options.
ft = fittype( 'a1*exp(-(x-x0).^2/(2*sigmax^2)-(y-y0).^2/(2*sigmay^2))+2.99', 'independent', {'x', 'y'}, 'dependent', 'z' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.368828021527717 0.246978644274972 0.833360541156488 0.184178747854432 0.278709178841745];
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, opts );
% Plot fit with data.
figure( 'Name', 'gauss_2d' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'gauss_2d', 'submatrix_red vs. X, Y', 'Location', 'NorthEast' );
% Label axes
xlabel X
ylabel Y
zlabel submatrix_red
grid on
view( 101.9, 2.2 );