# Getting the piecewise polynomial function of a 3D plot

9 views (last 30 days)

Show older comments

Is there a method to get the piecewise function of the 3D plot below? My requirement is to get a value for X as the output when Y and Z are given as inputs. The plot is created using the curve fitting tool (linear interpolation)

Inputs should be - z , y

Output should be - x

##### 3 Comments

ANKUR KUMAR
on 16 Mar 2021

Why are you using fitting tool GUI? You can do the same using interpolation code in a script.

DGM
on 16 Mar 2021

### Answers (1)

ANKUR KUMAR
on 16 Mar 2021

Edited: ANKUR KUMAR
on 16 Mar 2021

You can use interp2 to calculate values programmatically.

clc

clear

[X,Y] = meshgrid(-5:1:5);

Z = Y.*sin(X) - 5*X.*cos(2*Y);

s = surf(X,Y,Z,'FaceAlpha',0.5);

[XX,YY] = meshgrid(-5:0.05:5);

ZZ=interp2(X,Y,Z,XX,YY);

figure

s = surf(XX,YY,ZZ,'FaceAlpha',0.5);

s.EdgeColor = 'none';

x_reqired=randi(50,1,10)/10;

y_reqired=randi(50,1,10)/10;

z_reqired=interp2(X,Y,Z,x_reqired,y_reqired)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!