-
fundamental form
& gt& gty =[0 0.58 0.70 0.95 0.83 0.25];
& gt& gt drawing (y)
The generated graph is a dotted line drawn with the serial number as the abscissa and the numerical value of the array Y as the ordinate.
& gt& gtx=linspace(0,2*pi,30); % generates a set of linear equidistant values.
& gt& gty = sin(x);
& gt& gt drawing (x, y)
The generated graph is a smooth sine curve connected by 30 points.
multirow
You can draw many curves on the same screen, just give a few more arrays, such as
& gt& gtx = 0:pi/ 15:2 * pi;
& gt& gty 1 = sin(x);
& gt& gty2 = cos(x);
& gt& gt drawing (x, y 1, x, y2)
You can draw multiple lines. Another drawing method is to use the hold command. If hold on is set on the already drawn graph, MATLA will draw the graph generated by the new plot command on the original graph. The command hold off will end the process. For example:
& gt& gtx=linspace(0,2*pi,30); y = sin(x); Drawing (x, y)
& gt& gt Continue
& gt& gtz = cos(x); Drawing (x, z)
& gt& gt procrastination
Linetype and color
MATLAB has many choices for the line type and color of curves. The method of marking is to add a string parameter after each pair of arrays, which is explained as follows:
Linear mode:-solid line: dotted line-. Dashed line-broken line.
Linear point method:. Dot+plus sign * asterisk x x O small circle
Color: y yellow; R red; G green; B blue; W white; K black; M purple; C green.
Use the following examples to illustrate the usage:
& gt& gtx = 0:pi/ 15:2 * pi;
& gt& gty 1 = sin(x); y2 = cos(x);
& gt& gtplot(x,y 1,' b:+',x,y2,' g-。 *')
Grids and markers
You can add grids, titles, X-axis markers and Y-axis markers to a chart and use the following commands to accomplish these tasks.
& gt& gtx=linspace(0,2*pi,30); y = sin(x); z = cos(x);
& gt& gt drawing (x, y, x, z)
& gt& gt lattice
& gt& gtxlabel ('independent variable x')
& gt& gtylabel ("dependent variables y and z")
& gt& gt Title ("Sine and Cosine Curves")
You can also add strings anywhere in the drawing, for example, using:
& gt& gt text (2.5, 0.7,' sinx')
It means adding the string sinx at coordinates x = 2.5 and y = 0.7. It is more convenient to use the mouse to determine the position of the string by entering the following command:
& gt& gtgtext('sinx ')
The intersection of the crosshairs in the graphics window is the position of the string, where you can put the string by clicking the mouse.
Coordinate system control
By default, MATLAB automatically selects the ratio of horizontal and vertical coordinates of the graph. If you are not satisfied with this ratio, you can use the axis command to control it. Commonly used are:
Axis([xmin xmax ymin ymax]) [] gives the maximum and minimum values of the X axis and the Y axis respectively.
Axis equal or axis ('equal') The unit length of X axis and Y axis is the same.
Axis square or axis ('square') drawing box is square.
Axis off or axis ('off') clears the coordinate scale.
And the normal axis on the axis (axis) of the automatic axis image axis xy axis ij axis.
Please refer to the online help system for usage.
Multiple graphics
You can set several coordinate systems on the same screen and use subordinate (m, n, p) commands; Divide a picture into m×n graphic regions, where p represents the current region number, and draw a picture in each region, for example
& gt& gtx=linspace(0,2*pi,30); y = sin(x); z = cos(x);
& gt& gtu=2*sin(x)。 * cos(x); v=sin(x)。 /cos(x);
> > Sub-plot (2,2, 1), plot (x, y), axis ([0 2 * pi–11]), title ('sin(x)')
> > Subplot (2,2,2), Plot (x, z), Axis ([0 2 * pi–11]), Title ('cos(x)').
& gt& gtsubplot(2,2,3),plot(x,u),axis([0 2 * pi– 1 1]),title('2sin(x)cos(x)')
> > subplots (2, 2, 4), plots (x, v), axes ([0 2 * pi–20 20]), and titles ('sin(x)/cos(x)').
Graphic output
In mathematical modeling, it is often necessary to output the generated graphics to Word documents. Generally, the following methods can be adopted:
Firstly, select the export option in the file menu in the MATLAB graphics window and open the graphics output dialog box, which can save the graphics in emf, bmp, jpg, pgm and other formats. Then, open the corresponding document, select the "Picture" option in the "Insert" menu, and insert the corresponding picture in the document.