MATLAB Examples

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

Read about the surf function in the MATLAB documentation.

For more examples, 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)