Curve Fitting Tool, generated code issues

3 visualizaciones (últimos 30 días)
Ingo Rück
Ingo Rück el 16 de Ag. de 2017
Comentada: Kris Fedorenko el 24 de Ag. de 2017
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 comentarios
Ingo Rück
Ingo Rück el 24 de Ag. de 2017
" 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 el 24 de Ag. de 2017
I am glad it helped!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by