0
votes

I have a irregular set of data points in the form of cartesian coordinates which using the MATLAB cftool can be turned into a surface (see below).

MATLAB cftool surface

Does anyone know a way to access the matrix of cartesian coordinates that MATLAB generates in order for it to plot this surface?

The code generated for this graph (seen below) provides no access to the any additional interpolated points which must be produced to fit the surface.

%% Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( x1, y1, z1 );

% Set up fittype and options.
ft = 'linearinterp';

% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );

% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'z1 vs. x1, y1', 'Location', 'NorthEast' );
% Label axes
xlabel x1
ylabel y1
zlabel z1
grid on

Thanks in advance

1

1 Answers

1
votes

As a possible workaround (potentially not very efficient) is to plot the output of the fit (fitresult) and fetch the XData, YData and ZData properties of the plotted surface.

For example, after performing a dummy fit:

hP = plot(fitresult)

yields those properties for hP:

Surface (curvefit.gui.FunctionSurface) with properties:

       EdgeColor: [0 0 0]
       LineStyle: '-'
       FaceColor: 'flat'
    FaceLighting: 'flat'
       FaceAlpha: 1
           XData: [51x49 double]
           YData: [51x49 double]
           ZData: [51x49 double]
           CData: [51x49 double]

So you can retrieve them.

ALTERNATIVE

as an alternative, you could use the code generated by cftool to provide additional output arguments to the function (called createFit or somethinbg like this). Therefore, as you call the function with enough arguments you will obtain those coordinates directly.

Example:

change the header of the generated function like so:

[fitresult, gof,a,b,c] = createFit1(x, y, z)

and then in the function body:

a = xData;
b = yData;
c = zData;

then calling the function in the Command Window, for example, yields the right coordinates in a,b and c.