Xlabel (' Jeff ')% to axes plus description
Title (' Xmax ')% add graph to whole graph
Grid% plus grid
T=0:.1:2*pi drawing from 0 to 2pi
X^2 represents a matrix multiplication, while x.^2 represents a numeric multiplication.
common Two-dimensional graphical commands:
Plot: Draw two-dimensional graphics
Loglog: Plotting with full logarithmic coordinates
SEMILOGX: Plotting with semi-logarithmic coordinates (X)
fill: Draw Two-dimensional, multi-filled graphics
Polar: Drawing Polar plots
Bar: Draw a bar chart
stem: Draw discrete sequence data graph
Stairs: Drawing ladder Diagram
ErrorBar: Drawing error Bar chart
hist: Picture histogram Fplot: Drawing function Diagram
text: Textual annotations
Grid : Two dimensional three-dimensional graphics plus grille
Draw a single two-dimensional curve:
The plot function, the basic invocation format is:
Plot (x, y)
where x and y are vectors of the same length, respectively, for storing x-coordinate and y-coordinate data.
For example: Within the 0≤x≤2 interval, draw the curve Y=2e-0.5xcos (4πx)
The procedure is as follows:
X=0:pi/100:2*pi;
Y=2*exp ( -0.5*x). *cos (4*pi*x);
Plot (x, y)
The simplest invocation format for the plot function is to include only one input parameter:
Plot (x)
In this case, when x is a real vector, with the subscript of the vector element as the horizontal axis, the element value is the ordinate to draw a continuous curve, which is actually to draw a line chart.
P=[22,60,88,95,56,23,9,10,14,81,56,23];
Plot (P)
Draw multiple two-dimensional curves:
For example: Draw curves Y1=0.2e-0.5xcos (4πx) and Y2=2e-0.5xcos (πx) in the same coordinates with different scales.
The procedure is as follows:
X=0:pi/100:2*pi;
Y1=0.2*exp ( -0.5*x). *cos (4*pi*x);
Y2=2*exp ( -0.5*x). *cos (pi*x);
Plotyy (x,y1,x,y2);
Graph hold:
The hold on/off command controls whether to keep the original shape or refresh the original shape, and the holding command without parameters toggles between the two states.
For example, to draw a curve within the same coordinates using a graph hold
Y1=0.2e-0.5xcos (4πx) and Y2=2e-0.5xcos (πx).
The procedure is as follows:
X=0:pi/100:2*pi;
Y1=0.2*exp ( -0.5*x). *cos (4*pi*x);
Plot (X,Y1)
On
Y2=2*exp ( -0.5*x). *cos (pi*x);
Plot (x,y2);
Hold off
Set curve style
Determines the linetype, color, and data point marker symbols for the plotted curve, which can be used in combination. For example, "B-." Represents a blue dash, "y:d" denotes a yellow dashed line and marks a data point with a diamond character. When an item is omitted, the default linetype is all solid, and the color is followed by the order of the curve.
For example: in the same coordinates, the curves Y1=0.2e-0.5xcos (4πx) and Y2=2e-0.5xcos (πx) are plotted with different linetype and colors, marking the intersection of the two curves.
The procedure is as follows:
X=linspace (0,2*pi,1000);
Y1=0.2*exp ( -0.5*x). *cos (4*pi*x);
Y2=2*exp ( -0.5*x). *cos (pi*x);
K=find (ABS (Y1-Y2) <1e-2); % find subscript for Y1 and Y2 equal points (approximately equal)
X1=x (k); % y1 x coordinate with y2 equal point
Y3=0.2*exp ( -0.5*x1). *cos (4*PI*X1); % to find the y-coordinate of the Y1 and Y2 values equal points
Plot (X,y1,x,y2, ' K: ', X1,y3, ' BP ');
Graphical dimensioning and coordinate control
1. Graphic callouts
The calling format for the graphical callout function is:
Title (graphic name)
Xlabel (X-axis description)
Ylabel (Y-axis description)
Text (x, y, graphical description)
Legend (Fig. 1, fig. 2,...)
For example: Within the 0≤x≤2 interval, draw curves y1=2e-0.5x and Y2=cos (4πx) and add graphical callouts to the graph.
The procedure is as follows:
X=0:pi/100:2*pi;
Y1=2*exp ( -0.5*X);
Y2=cos (4*PI*X);
Plot (X,y1,x,y2)
Title (' x from 0 to 2{\pi} '); % plus graphic title
Xlabel (' Variable X '); % plus x Axis description
Ylabel (' Variable Y '); % plus y-axis description
Text (0.8,1.5, ' curve y1=2e^{-0.5x} ');% add a graphical description at the specified position
Text (2.5,1.1, ' curve y2=cos (4{\pi}x) ');
Legend (' y1 ', ' y2 ')% plus legend
Coordinate control
The call format for the
axis function is:
axis ([xmin xmax ymin ymax zmin Zmax])
axis functions are rich in functionality and are commonly used in the following formats:
axis equal: vertical and horizontal axes with equal length scale.
Axis Square: Produces a square coordinate system (the default is a rectangle).
Axis Auto: Use the default settings.
Axis off: cancels the axis.
Axis on: Displays the axes.
For example, the Grid command is used to control coordinates and grid lines. The grid on/off command controls whether a grid line is drawn or not drawn, and the grid command without parameters toggles between the two states. The
controls the coordinates with the box command. box on/OFF command controls whether to add or no border lines, the box command without parameters toggles between two states
in the same coordinate, you can draw 3 concentric circles, and coordinate control. The
program is as follows:
T=0:0.01:2*pi;
X=exp (i*t);
Y=[x;2*x;3*x] ';
Plot (y)
grid on;% plus grid line
box on;% plus coordinate border
axis equal% axis with equal scale
Two-dimensional statistical analysis diagram
In Matlab, the two-dimensional statistical analysis of a lot of graphics, the common bar chart, Ladder diagram, rod and fill charts, etc., the functions used are:
Bar (x, y, Options): Draw a bar chart
Stairs (x, Y, Options): Draw Ladder Diagram
Stem (x, Y, Options): Draw discrete sequence data graph
Examples are plots of curve y=2sin (x) in the form of bar, ladder, bar, and fill charts, respectively.
The procedure is as follows:
X=0:pi/10:2*pi;
Y=2*sin (x);
Subplot (2,2,1); bar (x, y, ' G ');
Title (' Bar (x, y, ' g ') '); axis ([0,7,-2,2]);
Subplot (2,2,2); Stairs (x, y, ' B ');
Title (' Stairs (x, y, ' B ') '), axis ([0,7,-2,2]);
Subplot (2,2,3); Stem (x, y, ' k ');
Title (' Stem (x, y, ' k ') '); axis ([0,7,-2,2]);
Subplot (2,2,4); Fill (x, y, ' y ');
Title (' Fill (x, y, ' y ') '); axis ([0,7,-2,2]);
LL (x1,y1, option 1,x2,y2, option 2,...) : Fill Graphics
MATLAB provides a number of statistical analysis plotting functions, for example, a pie chart that represents the percentage of each element as a sum, a complex number of phasor graphs, and so on.
Example to draw a graph:
(1) The annual output value of an enterprise (unit: million) is: 2347,1827,2043,3025, trial pie chart for statistical analysis.
(2) Plot of complex numbers: 7+2.9i, 2-3i and -1.5-6i.
The procedure is as follows:
Subplot (1,2,1);
Pie ([2347,1827,2043,3025]);
Title (' Pie chart ');
Legend (' One quarter ', ' two quarter ', ' three quarter ', ' four Quarter ');
Subplot (1,2,2);
Compass ([7+2.9i,2-3i,-1.5-6i]);
z=[];% defines an initial value of NULL for
I=1:3%3 is the arbitrary number of n that I take, you are the number of x, y that you want to enter
x=input (' x= ');
t=[x,y];% a set of X, y into the T-matrix
z=[z;t];% The 3 sets of different x, y into the z-matrix, Z is an n-row (here is 3) 2 columns of the matrix
end
x=z (:, 2);% assigns the z minus the second column to the X matrix, This is X is an n row 1 column of the Matrix
y=z (:, 1);% takes the second column of z assigned to the Y-matrix
plot (X ', Y ')% here, we want to transpose the 2 column vectors, and plot the line vectors.
this you copy it into the editor, save, in the command window to enter the saved name can be entered into the data, after recording 3 groups can be out of the picture.
x=[0.02,0.05,0.08];
Y=[86.18,80.16,76.64];
Figure