Curve Fitting Toolbox for Surface Extrapolation

12 views (last 30 days)
Hi everyone,
I am working with a fairly simple X,Y, Z dataset to extrapolate some datapoints outside of the data region. I have used the Curve Fitting toolbox to fit a surface to the datapoints which seems pretty good. I have used the toolbox to generate the code which can be found below. It shows me a nice figure which I am happy with. Unfortunately, I don't know how to use this surface.
My aim is to feed in xq, and xy values and it would tell me zq. How can I achieve this?
Many thanks.
% Data for 'Lowess' fit:
% X Input : BH_X
% Y Input : BH_Y
% Z Output: BH_Z
%% Fit: 'Lowess'.
[xData, yData, zData] = prepareSurfaceData( BH_X, BH_Y, BH_Z );
% Set up fittype and options.
ft = fittype( 'loess' );
opts = fitoptions( 'Method', 'LowessFit' );
opts.Normalize = 'on';
opts.Robust = 'Bisquare';
opts.Span = 0.2;
% Fit model to data.
[fitresult{2}, gof(2)] = fit( [xData, yData], zData, ft, opts );
% Create a figure for the plots.
figure( 'Name', 'Lowess' );
% Plot fit with data.
subplot( 2, 1, 1 );
h = plot( fitresult{2}, [xData, yData], zData );
legend( h, 'Lowess', 'BH_Z vs. BH_X, BH_Y', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'BH_X', 'Interpreter', 'none' );
ylabel( 'BH_Y', 'Interpreter', 'none' );
zlabel( 'BH_Z', 'Interpreter', 'none' );
grid on
view( -1.3, 14.3 );
% Plot residuals.
subplot( 2, 1, 2 );
h = plot( fitresult{2}, [xData, yData], zData, 'Style', 'Residual' );
legend( h, 'Lowess - residuals', 'Location', 'NorthEast', 'Interpreter', 'none' );
% Label axes
xlabel( 'BH_X', 'Interpreter', 'none' );
ylabel( 'BH_Y', 'Interpreter', 'none' );
zlabel( 'BH_Z', 'Interpreter', 'none' );
grid on
view( -1.3, 14.3 );

Accepted Answer

Torsten
Torsten on 19 Sep 2022
[fitresult, gof] = fit( [xData, yData], zData, ft, opts );
xq = (xData(1)+xData(2))/2;
yq = (yData(1)+yData(2))/2;
zq = feval(fitresult,[xq yq])
  2 Comments
Torsten
Torsten on 19 Sep 2022
Edited: Torsten on 19 Sep 2022
Just test values for interpolation in [xq yq].

Sign in to comment.

More Answers (1)

William Rose
William Rose on 19 Sep 2022

Community Treasure Hunt

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

Start Hunting!