Function from graphics in MATLAB

2D and 3D plots

Line plots

Use the function to create two-dimensional line plots. For example, you can use it to plot the value of the sine function from 0 to:

x = 0: pi / 100: 2 * pi; y = sin (x); plot (x, y)

You can label the axes and add a title.

xlabel ('x') ylabel ('sin (x)') title ('Plot of the Sine Function')

By adding a third input argument to the function, you can plot the same variables using a red dashed line.

is a Line specification. Each specification can include characters for line color, line style, and markings. A marker is a symbol that appears at each plotted data point, for example, or. For example, a green dotted line with markings () requests.

Notice that the titles and labels you defined for the first plot are no longer in the current one Illustrationwindow. By default, MATLABĀ® deletes the image every time you call up a plot function or reset the axes and other elements in order to prepare the new plot.

If you want to add plots to an existing figure, use the command. Until you use or close the window, all plots are displayed in the current figure window.

x = 0: pi / 100: 2 * pi; y = sin (x); plot (x, y) hold on y2 = cos (x); plot (x, y2, ':') legend ('sin', 'cos') hold off

3D plots

Three-dimensional plots are typically displayed with a surface that is represented by a function in two variables, z = f (x, y), is defined.

To evaluate z first create a set of dots (x, y) over the scope of the function using.

[X, Y] = meshgrid (-2: .2: 2); Z = X. * Exp (-X. ^ 2 - Y. ^ 2);

Then you create a surface plot.

Both the function and its accompanying function display surfaces in three dimensions. With the connection lines and the surfaces of the surfaces are displayed in color. Creates wireframe surfaces that show only the lines that connect defining points in color.

Subplots

The function allows you to display multiple plots in different sub-areas of the same window.

The first two entries for indicate the number of plots in each row and column. The third entry indicates which plot is active. For example, create four plots on a 2x2 grid in a mapping window.

t = 0: pi / 10: 2 * pi; [X, Y, Z] = cylinder (4 * cos (t)); subplot (2,2,1); mesh (X); title ('X'); subplot (2.2.2); mesh (Y); title ('Y'); subplot (2,2,3); mesh (Z); title ('Z'); subplot (2,2,4); mesh (X, Y, Z); title ('X, Y, Z');