image thumbnail

MATLAB Plot Gallery - Surface Plot (1)

by

 

24 Feb 2012 (Updated )

Create a surface plot

Surface_Plot_1

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
figure
surf(X, Y, Z)

Contact us