Surface plot - MATLAB surf (2024)

Surface plot

collapse all in page

  • Surface plot - MATLAB surf (1)

Syntax

surf(X,Y,Z)

surf(X,Y,Z,C)

surf(Z)

surf(Z,C)

surf(ax,___)

surf(___,Name,Value)

s = surf(___)

Description

example

surf(X,Y,Z) creates a three-dimensional surface plot, which is a three-dimensional surface that has solid edge colors and solid face colors. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y. The color of the surface varies according to the heights specified by Z.

example

surf(X,Y,Z,C) additionallyspecifies the surface color.

surf(Z) creates a surface plot and uses the column and row indices of the elements in Z as the x- and y-coordinates.

surf(Z,C) additionallyspecifies the surface color.

surf(ax,___) plotsinto the axes specified by ax instead of the currentaxes. Specify the axes as the first input argument.

example

surf(___,Name,Value) specifies surface properties using one or more name-value pair arguments. For example, 'FaceAlpha',0.5 creates a semitransparent surface.

example

s = surf(___) returns the chart surface object. Use s to modify the surface after it is created. For a list of properties, see Surface Properties.

Examples

collapse all

Create Surface Plot

Open Live Script

Create three matrices of the same size. Then plot them as a surface. The surface plot uses Z for both height and color.

[X,Y] = meshgrid(1:0.5:10,1:20);Z = sin(X) + cos(Y);surf(X,Y,Z)

Surface plot - MATLAB surf (2)

Specify Colormap Colors for Surface Plot

Open Live Script

Specify the colors for a surface plot by including a fourth matrix input, C. The surface plot uses Z for height and C for color. Specify the colors using a colormap, which uses single numbers to stand for colors on a spectrum. When you use a colormap, C is the same size as Z. Add a color bar to the graph to show how the data values in C correspond to the colors in the colormap.

[X,Y] = meshgrid(1:0.5:10,1:20);Z = sin(X) + cos(Y);C = X.*Y;surf(X,Y,Z,C)colorbar

Surface plot - MATLAB surf (3)

Specify True Colors for Surface Plot

Open Live Script

Specify the colors for a surface plot by including a fourth matrix input, CO. The surface plot uses Z for height and CO for color. Specify the colors using truecolor, which uses triplets of numbers to stand for all possible colors. When you use truecolor, if Z is m-by-n, then CO is m-by-n-by-3. The first page of the array indicates the red component for each color, the second page indicates the green component, and the third page indicates the blue component.

[X,Y,Z] = peaks(25);CO(:,:,1) = zeros(25); % redCO(:,:,2) = ones(25).*linspace(0.5,0.6,25); % greenCO(:,:,3) = ones(25).*linspace(0,1,25); % bluesurf(X,Y,Z,CO)

Surface plot - MATLAB surf (4)

Modify Surface Plot Appearance

Open Live Script

Create a semitransparent surface by specifying the FaceAlpha name-value pair with 0.5 as the value. To allow further modifications, assign the surface object to the variable s.

[X,Y] = meshgrid(-5:.5:5);Z = Y.*sin(X) - X.*cos(Y);s = surf(X,Y,Z,'FaceAlpha',0.5)

Surface plot - MATLAB surf (5)

s = Surface with properties: EdgeColor: [0 0 0] LineStyle: '-' FaceColor: 'flat' FaceLighting: 'flat' FaceAlpha: 0.5000 XData: [21x21 double] YData: [21x21 double] ZData: [21x21 double] CData: [21x21 double] Use GET to show all properties

Use s to access and modify properties of the surface object after it is created. For example, hide the edges by setting the EdgeColor property.

s.EdgeColor = 'none';

Surface plot - MATLAB surf (6)

Input Arguments

collapse all

Xx-coordinates
matrix | vector

x-coordinates, specified as a matrix the same size as Z, or as a vector with length n, where [m,n] = size(Z). If you do not specify values for X and Y, surf uses the vectors (1:n) and (1:m).

You can use the meshgrid function to create X and Y matrices.

The XData property of the Surface object stores the x-coordinates.

Example: X = 1:10

Example: X = [1 2 3; 1 2 3; 1 2 3]

Example: [X,Y] = meshgrid(-5:0.5:5)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Yy-coordinates
matrix | vector

y-coordinates, specified as a matrix the same size as Z or as a vector with length m, where [m,n] = size(Z). If you do not specify values for X and Y, surf uses the vectors (1:n) and (1:m).

You can use the meshgrid function to create the X and Y matrices.

The YData property of the surface object stores the y -coordinates.

Example: Y = 1:10

Example: Y = [1 1 1; 2 2 2; 3 3 3]

Example: [X,Y] = meshgrid(-5:0.5:5)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

Zz-coordinates
matrix

z-coordinates, specified as a matrix. Z must have at least two rows and two columns.

Z specifies the height of the surface plot at each x-y coordinate. If you do not specify the colors, then Z also specifies the surface colors.

The ZData property of the surface object stores the z -coordinates.

Example: Z = [1 2 3; 4 5 6]

Example: Z = sin(x) + cos(y)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | categorical | datetime | duration

CColor array
matrix | m-by-n-by-3 array of RGB triplets

Color array, specified as an m-by-n matrix of colormap indices or as an m-by-n-by-3 array of RGB triplets, where Z is m-by-n.

  • To use colormap colors, specify C as a matrix. For each grid point on the surface, C indicates a color in the colormap. The CDataMapping property of the surface object controls how the values in C correspond to colors in the colormap.

  • To use truecolor colors, specify C as an array of RGB triplets.

For more information, see Differences Between Colormaps and Truecolor.

The CData property of the surface object stores the color array. For additional control over the surface coloring, use the FaceColor and EdgeColor properties.

axAxes to plot in
axes object

Axes to plot in, specified as an axes object. If you do not specify the axes, then surf plots into the current axes.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: surf(X,Y,Z,'FaceAlpha',0.5,'EdgeColor','none') createsa semitransparent surface with no edges drawn.

Note

The properties listed here are only a subset. For a full list,see Surface Properties.

Extended Capabilities

Version History

Introduced before R2006a

See Also

Functions

  • colormap | pcolor | meshgrid | imagesc | shading | view | mesh

Properties

  • Surface Properties

Topics

  • Representing Data as a Surface
  • How Surface Plot Data Relates to a Colormap

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Surface plot - MATLAB surf (7)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Surface plot - MATLAB surf (2024)

FAQs

Surface plot - MATLAB surf? ›

surf( Z ) creates a surface plot and uses the column and row indices of the elements in Z as the x- and y-coordinates. surf( Z , C ) additionally specifies the surface color. surf( ax ,___) plots into the axes specified by ax instead of the current axes. Specify the axes as the first input argument.

How to plot coastline in MATLAB? ›

This can be done by calling axesm first, and then plotting using pcolorm and geoshow:
  1. load coastlines.
  2. axesm("eqaconic","MapLatLimit",[-57 -43],"MapLonLimit",[130 160])
  3. pcolorm(lat,lon,ctt)
  4. geoshow(coastlat,coastlon)
Jul 25, 2019

What is the difference between Ezsurf and surf in MATLAB? ›

The ezsurf function does not plot points where the mathematical function is not defined. These points are set to NaN so that they do not plot. Use surf to plot the same data without filtering discontinuities.

What is the difference between mesh and surf in MATLAB? ›

mesh produces wireframe surfaces that color only the lines connecting the defining points. surf displays both the connecting lines and the faces of the surface in color. The figure colormap and figure properties determine how MATLAB colors the surface.

What is Surf X Y Z in MATLAB? ›

surf( X , Y , Z ) creates a three-dimensional surface plot, which is a three-dimensional surface that has solid edge colors and solid face colors. The function plots the values in matrix Z as heights above a grid in the x-y plane defined by X and Y .

How to plot using surf in matlab? ›

surf( X , Y , Z , C ) additionally specifies the surface color. surf( Z ) creates a surface plot and uses the column and row indices of the elements in Z as the x- and y-coordinates. surf( Z , C ) additionally specifies the surface color. surf( ax ,___) plots into the axes specified by ax instead of the current axes.

How do you make a surf plot transparent in Matlab? ›

Set the properties to a scalar value in the range [0,1] . A value of 0 means completely transparent, a value of 1 means completely opaque, and values between 0 and 1 are semitransparent. Patch, surface, scatter, and image objects support using alpha data to vary the transparency across the object.

What is a surface mesh in MATLAB? ›

A surfaceMesh object creates and stores a surface mesh. A surface mesh represents a geometric surface and consists of vertices, faces, and edges. Using the surfaceMesh object and the object functions, you can: Add and remove mesh vertices and faces.

What is a surface plot? ›

Introduction. Surface plots are diagrams of three-dimensional data. Rather than showing the individual data points, surface plots show a functional relationship between a designated dependent variable (Y), and two independent variables (X and Z). The plot is a companion plot to the contour plot.

Why is my surface plot black in MATLAB? ›

The reason you get a surface that's all black is that the grid is too fine, so all you see are the black lines between grid cells. To fix it you can use a coarser grid, if that's an option, or you can turn the grid lines off by specifying 'EdgeColor','none' when the surface is created (or after it's created).

How to interpret a 3D surface plot? ›

Key Results: 3D Surface Plot

Heating at the shorter time intervals results in under-cooked product and low quality scores. However, heating at the longest intervals combined with the highest temperatures also results in low scores because the food becomes over-cooked.

How to extract surf features in MATLAB? ›

MathWorks Matrix Menu
  1. Feature Extraction Using SURF.
  2. Third-Party Prerequisites.
  3. Verify GPU Environment.
  4. Feature Extraction.
  5. Read Input Image.
  6. Generate CUDA MEX for the Function.
  7. Run SURF Detection on MATLAB and GPU.
  8. Depict the Extracted Interest Points.

What is the default view surf in MATLAB? ›

Default 2-D and 3-D Views

MATLAB automatically selects a viewpoint that is determined by whether the plot is 2-D or 3-D: For 2-D plots, the default is azimuth = 0° and elevation = 90°. For 3-D plots, the default is azimuth = -37.5° and elevation = 30°.

How to plot geographic data in Matlab? ›

geoplot( lat , lon ) plots a line in geographic coordinates. Specify latitude coordinates in degrees using lat , and specify longitude coordinates in degrees using lon . If the current axes is not a geographic or map axes, or if there is no current axes, then the function plots the line in a new geographic axes.

How do you plot a moving line in Matlab? ›

Display Line Animation

Create the initial animated line object. Then, use a loop to add 1,000 points to the line. After adding each new point, use drawnow to display the new point on the screen. For faster rendering, add more than one point to the line each time through the loop or use drawnow limitrate .

How to plot periodic square wave in matlab? ›

Generate Square Waves

t = linspace(0,3*pi)'; x = square(t); Plot the square wave and overlay a sine. Normalize the x-axis by π . The generated square wave has a value of 1 for intervals [ n π , ( n + 1 ) π ) with even n and a value of - 1 for intervals [ n π , ( n + 1 ) π ) with odd n .

How do you plot an area graph in Matlab? ›

area( X , Y ) plots the values in Y against the x-coordinates X . The function then fills the areas between the curves based on the shape of Y : If Y is a vector, the plot contains one curve. area fills the area between the curve and the horizontal axis.

Top Articles
The Chili Recipes You Need To Survive The Cold Weather
Tofu and Kimchi Dumplings Recipe
Dainty Rascal Io
$4,500,000 - 645 Matanzas CT, Fort Myers Beach, FL, 33931, William Raveis Real Estate, Mortgage, and Insurance
Kevin Cox Picks
No Limit Telegram Channel
Unblocked Games Premium Worlds Hardest Game
Lifebridge Healthstream
Get train & bus departures - Android
Health Benefits of Guava
Otterbrook Goldens
Apply A Mudpack Crossword
Craigslist Estate Sales Tucson
Full Range 10 Bar Selection Box
Cranberry sauce, canned, sweetened, 1 slice (1/2" thick, approx 8 slices per can) - Health Encyclopedia
Explore Top Free Tattoo Fonts: Style Your Ink Perfectly! 🖌️
Citymd West 146Th Urgent Care - Nyc Photos
Where does insurance expense go in accounting?
Costco Gas Foster City
Parent Resources - Padua Franciscan High School
Loves Employee Pay Stub
Jeff Now Phone Number
Barber Gym Quantico Hours
Where to eat: the 50 best restaurants in Freiburg im Breisgau
Greensboro sit-in (1960) | History, Summary, Impact, & Facts
Albert Einstein Sdn 2023
Dove Cremation Services Topeka Ks
Miles City Montana Craigslist
Wonder Film Wiki
Is Poke Healthy? Benefits, Risks, and Tips
Rainfall Map Oklahoma
How To Improve Your Pilates C-Curve
Primerica Shareholder Account
FREE Houses! All You Have to Do Is Move Them. - CIRCA Old Houses
What are the 7 Types of Communication with Examples
Rubmaps H
Hotel Denizen Mckinney
CARLY Thank You Notes
Mistress Elizabeth Nyc
Www Craigslist Com Brooklyn
877-292-0545
Tsbarbiespanishxxl
Lonely Wife Dating Club בקורות וחוות דעת משתמשים 2021
Live Delta Flight Status - FlightAware
Penny Paws San Antonio Photos
Flappy Bird Cool Math Games
Mauston O'reilly's
How to Find Mugshots: 11 Steps (with Pictures) - wikiHow
99 Fishing Guide
Spongebob Meme Pic
Zalog Forum
Inloggen bij AH Sam - E-Overheid
Latest Posts
Article information

Author: Otha Schamberger

Last Updated:

Views: 5488

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Otha Schamberger

Birthday: 1999-08-15

Address: Suite 490 606 Hammes Ferry, Carterhaven, IL 62290

Phone: +8557035444877

Job: Forward IT Agent

Hobby: Fishing, Flying, Jewelry making, Digital arts, Sand art, Parkour, tabletop games

Introduction: My name is Otha Schamberger, I am a vast, good, healthy, cheerful, energetic, gorgeous, magnificent person who loves writing and wants to share my knowledge and understanding with you.