-->

# Create Plot 2-D, 3-D Matlab

The following will briefly explain the use of plot functions to plot 2-D and 3-D graphics. Readers are advised to view and read the HELP feature to get more complete information. If the plot function is called, the Figure window will open. The default is to plot dots and be connected in a straight line. Example,

plot (x, y)

the statement above will instruct MATLAB to plot values in vector x on a flat axis and values in vector y on the upright axis, and are connected by a straight line. The vectors must be the same size, for example:
Many variables can be used as arguments for plots. For example, the following command to plot two curves on the same axis,

plot (x, y1, x, y2)

The following is an example of making a plot.

If there is only one argument in the plot function, MATLAB plots a vector with an index of the values in the verktor.

The default for a curve is a solid line, but MATLAB has other options. The table below provides several line type choices,

 Notation Description - Solid line : Dotted line -. Dash-dot line -- Dashed line

If several lines are plotted on one set of axes, MATLAB plots with a different color. Colors can be predetermined where the operators used can be seen in the following table,

 Notation Description
 b Blue g Green r Red c Sian m Magenta y Yellow k Black w White

The symbol plot (*, x, 0, etc.) can also be used to plot points. The following table contains notation symbols that can be used for plots,

 Notation Description . dot o circle x x sign + plus * star s rectangular d diamond v triangle down ^ triangle up < triangle to the left > triangle to the right p pentagon h hexagon

To plot a curve where the points and connecting lines exist, can use the following command,

plot (x, y, x, y, 'b *')

the command above, first plots the points on x and y, connecting them in a straight line. Next plot the points on x and y using the * symbol in blue.

The following is an example of making a plot using types of lines, colors, and symbols.

The workings of the plot3 function are the same as the plot, except the vector now has three. Example,

plot3 (x, y, z)

All types of lines, colors and symbols can be applied to plot3. another form of plot from the 3-D plot is surf and mash. Axis titles and labels can be made for all plots using title, x-label, y-label, and z-label.

The following is an example of using plot3,

The following is an example of using surf

% Make normal bivariate standards.
% First: make points for the domain.
[x, y] = meshgrid (-3: .1: 3, -3: .1: 3);
% Evaluates by using normal bivariate standards.
z = (1 / (2 * pi)) * exp (-0.5 * (x. ^ 2 + y. ^ 2));
% Memplot as a surface plot.
surf (x, y, z)

There is one way to place multiple axes or plots in one window Figure. This is done by using the subplot function. This function creates a matrix plot (axis) m x n in the Figure window. The following is given an example of how to make two plots.

% Make the leftmost plot
subplot (1,2,1)
plot (x, y)
% Make the rightmost plot
subplot (1,2,2)
plot (x, z)

the first two arguments in the subplot tell MATLAB about the plot layout in the figure window. The third argument tells MATLAB the location or number of the plot. Olot-plots are numbered from top to bottom and from left to right.