Curve Fitting Tool, generated code issues

1 回表示 (過去 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 Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by