image thumbnail

MATLAB Plot Gallery - Surface Plot (1)



Create a surface plot


This is an example of how to create a surface plot in MATLAB®.

Read about the surf function in the MATLAB® documentation.

Go to MATLAB Plot Gallery

% Create a grid of x and y points
points = linspace(-2, 2, 40);
[X, Y] = meshgrid(points, points);

% Define the function Z = f(X,Y)
Z = 2./exp((X-.5).^2+Y.^2)-2./exp((X+.5).^2+Y.^2);

% Create the surface plot using the surf command
surf(X, Y, Z);

Contact us