How to create the Surf plot in MATLAB?

 

Syntax:

In the surface plot, ‘surf’ function is used. So, you can write a simple format like ‘function name(array)’.

surf(x,y,z)

surf(z)

MATLAB Code:

Let’s write a MATLAB code for the three-dimensional surface plot for an exponential function exp().

[x,y] = peaks(30);
z = exp(-0.9*(x.^2+0.5*(x-y).^2));
surf(x,y,z);
xlabel('\bf X axis');
ylabel('\bf Y axis');
zlabel('\bf Z axis');
title('\bf Surface Plot')
colorbar

Output in MATLAB:

After the getting output of surface plot, you will see the connecting lines and the faces are both displayed in the same shade.

3. Ribbon 3D Plot in MATLAB