-
Notifications
You must be signed in to change notification settings - Fork 4
/
createFit.m
38 lines (30 loc) · 926 Bytes
/
createFit.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
function [fitresult, gof] = createFit(X, Y, Z)
%CREATEFIT1(X,Y,Z)
% Create a fit.
%
% Data for 'myfit' fit:
% X Input: X
% Y Input: Y
% 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 08-Jan-2024 19:37:04
%% Fit: 'myfit'.
[xData, yData, zData] = prepareSurfaceData( X, Y, Z );
% Set up fittype and options.
ft = fittype( 'poly42' );
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'myfit' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'myfit', 'Z vs. X, Y', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'X', 'Interpreter', 'none' );
ylabel( 'Y', 'Interpreter', 'none' );
zlabel( 'Z', 'Interpreter', 'none' );
grid on
view( -3.7, 26.8 );