This section describes some important plotting functions and provides several typical examples. The previously mentioned plotting tools fully utilize MATLAB's plotting functions and these functions to generate Image Code.

1. Create a vertex

The plot function can have many input formats: if Y is a single vector, plot (y) will generate a piecewise linear graph of Y related to element y; if you specify two vectors x, Y as the parameter, plot (x, y) will generate a graph of Y related to X.

For example:

The following statement uses the colon operator to create an X vector from 0 to 2 * pi. Calculate the sin value and draw the result:

X = 0: PI/100:2 * PI;

Y = sin (X );

Plot (x, y)

Now you can mark the axis and title. The/PI character creates the symbol pi:

Xlabel ('X = 0: 2/PI ')

Ylabel ('sine of X ')

Title ('plot of the sine function', 'fontsize', 12)

The figure is as follows:

2. Multiple datasets in a graph

X = 0: PI/100:2 * PI;

Y = sin (X );

Y2 = sin (X-. 25 );

Y3 = sin (X-. 5 );

Plot (X, Y, X, Y2, X, Y3)

The legend command is used to indicate various point sets.

Legend ('sin (x) ', 'sin (X-. 25)', 'sin (X-. 5 )')

3. specify the type and color of a line segment

Plot (X, Y, 'color _ style_marker ')

4. draw lines and labels

V. fictitious and complex data

6. draw from existing images

The hold command allows you to draw a point set in an existing graph. When you type: Hold on

MATLAB will not replace the existing graph, but will draw a new point set based on the existing graph. Re-mark the axis if necessary.

For example:

The following statement first creates an equal high point of a peaks function:

[X, y, z] = peaks;

Pcolor (x, y, z)

Shading interp

Then add the pseudo-color points of the same function:

Hold on

Contour (X, Y, Z, 20, 'k ')

Hold off

The hold on command combines pseudo-color points with contour lines, as shown in:

7. Figure window

To make a window as the current window, you can left-click the expected window or enter the following in the Command window:

Figure (n): n indicates the expected window

Open a window and specify it as the current window. Available:

Figure

To clear a window to create a new graph, run the following command:

CLF Reset

7. Multiple point sets in a figure

Subplot (m, n, p)

Indicates the P unit in the M * n matrix.

For example:

T = 0: PI/10:2 * PI;

[X, y, z] = cylinder (4 * Cos (t ));

Subplot (2, 2, 1); mesh (X)

Subplot (2, 2); mesh (y)

Subplot (2, 2, 3); mesh (z)

Subplot (2, 2, 4); mesh (x, y, z)

The statement is as follows: