Curve Fitting Tool, generated code issues
Ältere Kommentare anzeigen
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 Kommentare
Kris Fedorenko
am 23 Aug. 2017
Hi Ingo!
I tried but was unable to reproduce this issue. I might be able to help better if you could tell me the following:
- What happens if you try to change the z limits of the figure from the generated code? You can do it like so:
f = gcf;
f.CurrentAxes.ZLim = [50, 100];
- When you say that x and y axes are the same, are you referring both to the parameters you are passing to "createFit" and "cftool" AND to the visible axis ranges on both figures? It seems that on the second figure the data points are taking up a smaller portion of the axes.
- What release of MATLAB are you using?
- Are you seeing the same issue if you use this example data?
z = membrane + 1;
extent = linspace(1, -1, 31);
[x, y] = meshgrid(extent, extent);
Ingo Rück
am 24 Aug. 2017
Kris Fedorenko
am 24 Aug. 2017
I am glad it helped!
Antworten (0)
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!