Curve Fitting Tool, generated code issues

조회 수: 2 (최근 30일)
Ingo Rück
Ingo Rück 2017년 8월 16일
댓글: Kris Fedorenko 2017년 8월 24일
Hello everyone
I have used the Curve Fitting Tool box to fit a polynomial to a set of 3D points. The result can be seen below.
Now if I let the fitting tool generate a code and run the function with the same inputs, the result looks a lot different:
the x and y axis are the same (not allowed to show them). The z-axis ranges from 50 to 100 in the first image and from -7000 to 2000 in the 2nd one. Where did I go wrong here and is there any way to fix this? Here is the automatically generated code:
function [fitresult, gof] = createFit(x, y, z)
%CREATEFIT(X,Y,Z)
% Create a fit.
%
% Data for 'polynomial test' fit:
% X Input : x
% Y Input : y
% Z Output: z
% Weights : 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 16-Aug-2017 10:13:47
%%Fit: 'polynomial test'.
[xData, yData, zData, weights] = prepareSurfaceData( x, y, z, z );
% Set up fittype and options.
ft = fittype( 'poly53' );
opts = fitoptions( 'Method', 'LinearLeastSquares' );
opts.Normalize = 'on';
opts.Weights = weights;
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, opts );
% Plot fit with data.
figure( 'Name', 'polynomial test' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'polynomial test', 'z vs. x, y with z', 'Location', 'NorthEast' );
% Label axes
xlabel x
ylabel y
zlabel z
grid on
view( 125.7, 36.4 );
When I use interpolant on the points instead of polynomial, the result from the generated code fits the tool box however. Similar question can be found here, no answers yet.
Thanks for your help!
  댓글 수: 3
Ingo Rück
Ingo Rück 2017년 8월 24일
" What happens if you try to change the z limits of the figure from the generated code? " Ah, that helped. I didnt think that would be the problem, because the axis ranges for x and y were the same in both pictures.
Thanks for the help.
Kris Fedorenko
Kris Fedorenko 2017년 8월 24일
I am glad it helped!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by