meshz

Mesh surface plot with curtain

Description

example

meshz(X,Y,Z) creates a mesh plot with a curtain around it. A mesh plot is a three-dimensional surface that has solid edge colors and no 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 edge colors vary according to the heights specified by Z.

example

meshz(X,Y,Z,C) additionally specifies the color of the edges.

meshz(Z) creates a mesh plot with a curtain, and uses the column and row indices of the elements in Z as the x- and y-coordinates.

meshz(Z,C) additionally specifies the color of the edges.

meshz(ax,___) plots into the axes specified by ax instead of the current axes. Specify the axes as the first input argument.

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

Examples

collapse all

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

[X,Y] = meshgrid(-3:.125:3);
Z = peaks(X,Y);
meshz(X,Y,Z)

Specify the colors for a mesh plot and surrounding curtain by including a fourth matrix input, C. The mesh 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(-3:.125:3);
Z = peaks(X,Y);
C = gradient(Z);
meshz(X,Y,Z,C)
colorbar

Create a mesh plot with a curtain around it. 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 = meshz(X,Y,Z)

s = 
  Surface (meshz) with properties:

       EdgeColor: 'flat'
       LineStyle: '-'
       FaceColor: [1 1 1]
    FaceLighting: 'none'
       FaceAlpha: 1
           XData: [25x25 double]
           YData: [25x25 double]
           ZData: [25x25 double]
           CData: [25x25 double]

  Show all properties

Use s to access and modify properties of the mesh plot after it is created. For example, change the color of the mesh plot edges and surrounding curtain by setting the EdgeColor property.

s.EdgeColor = 'b';

Input Arguments

collapse all

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, meshz uses the vectors (1:n) and (1:m).

When X is a matrix, the values must be strictly increasing or decreasing along one dimension and remain constant along the other dimension. The dimension that varies must be the opposite of the dimension that varies in Y. You can use the meshgrid function to create X and Y matrices.

When X is a vector, the values must be strictly increasing or decreasing.

The XData properties 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

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, meshz uses the vectors (1:n) and (1:m).

When Y is a matrix, the values must be strictly increasing or decreasing along one dimension and remain constant along the other dimension. The dimension that varies must be the opposite of the dimension that varies in X. You can use the meshgrid function to create X and Y matrices.

When Y is a vector, the values must be strictly increasing or decreasing.

The YData properties of the surface objects store 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

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

Z specifies the height of the mesh plot at each x-y coordinate. If you do not specify the colors, then Z also specifies the mesh edge 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

Color array, specified as a an m-by-n matrix of colormap indices, where Z is m-by-n. For each grid point on the mesh 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.

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

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

Extended Capabilities

Introduced before R2006a