The drawing functions commonly used in MATLAB

Source: Internet
Author: User
Tags close close cos sin

Some operations on the command-line environment: (1) CLC erases a page of command window, the cursor goes back to the upper left corner (2) clear clears all variables from the workspace (3) CLF clears the contents of the graphics window

Command 1 figure

Feature to create a new drawing object. The graphic object is a separate window on the screen that can output graphics in the window.

Usage figure creates a new drawing object with the default property value.

Command 2 subplot

Functions generate and control multiple axes. Separates the current graphics window into several rectangular sections, and the different parts are labeled numerically by row direction. Each section has an axis, and the subsequent graphic is output in the current section.

Usage subplot (m,n,p) divides a graphics window into M*n small windows, creating an axis in the small window of the first page. The new axis becomes the current axis. If P is constant, create an axis with all the small Windows listed in P.

Command 3 hold

function to keep the graphic in the current graphics window. This command determines whether you can add only new drawing objects or overwrite existing drawing objects in the current axis.

Use hold on to preserve the current shape's property values from the current axis, and the graphics command that follows can only add graphics to the currently existing axis. However, when the data range of the new shape exceeds the range of the current axis, the command automatically changes the range of the axis to fit the new shape.

Hold off before drawing a new drawing, reset the axis properties to the default values.

Command 4 Axis

Scale and external display of functional axes

Use axis ([xmin xmax ymin Ymax]) to set the x-axis and y-axis range of the current axis.

Command 5 Close

function to close the specified graphics window.

Use close to close the current graphics window.

Second, matlab drawing parameter control

Command 1 Plot

Function This is the most basic, most commonly used drawing function for plotting linear two-dimensional graphs. When there are multiple curves, the loop uses the colors defined by the axis color order properties to differentiate the different curves, and then loops through the linetype defined by the Axis Linetype Order property to differentiate the different curves.

When plot is plotted, the type of control curve can be selected by four parameters.

1. Line Style (4 kinds)

The definition character

-

--

-.

Linear

Solid line (default value)

Crossed

Point line

Dot Dash

2. Line width

Specify the width of the line, and the value is an integer (in pixels)

Example: Plot (x, y, ' linewidth ', 4)

3. Color (8 kinds)

The definition character

R (red)

G (Green)

B (Blue)

C (Cyan)

Color

Red

Green

Blue color

Cyan

The definition character

M (Magenta)

Y (Yellow)

K (Black)

W (White)

Color

Magenta

Yellow

Black

White

4. Marker type (13 kinds)

The definition character

+

O (letter)

*

.

X

Type

Plus

Small Circle

Asterisk

Real Point

Crossing number

The definition character

D

^

V

>

<

Type

Rib shape

Upper Triangle

Lower Triangle

Right triangle

Left Triangle

The definition character

S

H

P

Type

Square

Positive Hex Star

Positive Pentagram

Third, MATLAB graphics to mark the function

Command 1 title

function to add a caption to the current axis. Each axes drawing object can have a caption. The title is positioned at the top of the axes.

Use the title (' String ') to place the string as the caption in the center of the current axis.

Command 2 xlabel, Ylabel

function to label the x and Y axes

Use Xlabel (' string '), Ylabel (' string ') to label the x and y axes of the current Axis object.

Command 3 grid

Function adds a divider line to the coordinate plane of a two-dimensional or three-dimensional graphic.

Use grid on to add a separator line to the current axis.

Grid off removes the divider line from the current axis.

The state in which the grid transforms the display or not of the divider line.

Command 4 Legend

Feature to add a legend to the graphic. This command displays a legend in a window that has multiple graphic object types (line chart, bar chart, pie chart, and so on). For each line, the chart displays the line's linetype, marker symbol, color, and so on, next to the user-given text label.

Usage legend (' string1 ', ' string2 ',..., POS) displays a legend for each part of the given data in the current axis with the specified text string, placing the legends at the specified location pos.

Command 5 gtext

function to place text in the current two-dimensional graphic with the mouse. When the cursor enters the graphics window, it becomes a large cross, indicating that the system is waiting for the user's action.

Usage gtext (' string ') waits for the user to click the mouse or keyboard while the cursor is inside a graphics window. If you press the mouse or keyboard, place the given text "string" at the cursor position

Command 6 text

function to create a text object in the current axis. The function text is a low-level function that creates a handle to a text graphic. You can use this function to display a string in the position specified in the drawing.

Use text (x, y, ' string ') to display the string on the location (x, y) specified in the drawing.

Command 7 Zoom

function to zoom in or out of a two-dimensional graphic. Zooming in or out changes the axis range.

Use zoom on to turn on the interactive zoom function. There are two ways to magnify a graphic when it is in an interactive magnification state:

Method 1: Click any point in the axis with the left mouse button to enlarge the graph one time, this operation can be made multiple times until the maximum display of MATLAB; Right-click within the axis to make the graph zoom in one time, which can be done multiple times until the drawing is restored.

Method 2: Drag the mouse over the part you want to enlarge, and the system zooms in on the selected area.

Command 8 num2str, Int2str

function converts a number or integer to a string for easy graphical labeling.

Use St = NUM2STR (x) to represent the variable x value as the string St.

St = INT2STR (x) represents the integer portion of the variable x as the string St.


matlab Functions

To display three-dimensional graphics, MATLAB provides a variety of functions. There are some functions that draw lines in three-dimensional space, while others can draw curved and wireframe frames. In addition, colors can be used to represent the fourth dimension. When the color is used in this way, it is called a pseudo-color because it no longer displays the natural properties of the information----color as in the photo, and is not intrinsic to the underlying data. To simplify the discussion of three-dimensional graphics, the introduction of colors is deferred to the next chapter. In this chapter, we mainly discuss the basic concepts of drawing three-dimensional graphs.
The functions discussed below and their characteristics are summarized in table 2, table 3, table 4, and table 5:
Table 2
Contour two-dimensional contour plot, that is, from the top down to the CONTOUR3 contour map contour3 contour map Fill3 filled polygon mesh grid diagram MESHC grid with basic contour map Meshz has a 0-plane grid diagram Pcolor Two-dimensional pseudo-color plot, From top to bottom surf figure plot3 Line graph quiver velocity graph with directional arrows surf surface chart Surfc surface chart with basic contour map SURFL surface with luminance waterfall grid with no cross line

Represents 3
Axis Correction Axis Properties clf Clear graphics window Clabel Place contour labels close close graphics window figure Create or Select Graphics window getframe snap Animation frame grid Place grid griddata data for paint interpolation hidden hidden grid line hold keep current diagram Shape Meshgrid produce three-dimensional drawing data movie animation Moviein create frame matrix, storage animation shading in the surface and pseudo-color map with the block, Smoothing and interpolation with shadows subplot in the graphics window inside the text text at the specified position place the title view change the view of the graphic Xlabel place the x-axis marker Ylabel Place the y-axis marker Zlabel Place the z-axis marker
Table 4
View (Az,el) Set the azimuth of the views AZ and Elevation Elview ([Az,el]) view ([x, Y, z]) in the Cartesian coordinate system, set the view along the vector [x, y, z] face origin, such as view ([0 0 1]) =view (0,90) view (2) Sets the default two-dimensional view, Az=0,el=90view (3) sets the default three-dimensional view, Az=-37.5,el=30[az,el]=view returns the current azimuth AZ and elevation Elview (t) with a 4x4 transpose matrix T to set the view t= View returns the current 4x4 transpose matrix
Table 5
Mmcont2 (x,y,z,c) Two-dimensional contour map with color image Mmcont3 (x,y,z,c) three-dimensional contour map with color image mmspin3d (N) rotate the three-dimensional azimuth of the current shape to animate mmview3d use the slide mark to adjust the angle of view
It is also a reminder that the reshape function of MATLAB is column-first, such as:
y = 1 2 3 4 5 6
Reshape (y,3,2) =
1 4
2 5
3 6
Instead of 1 2 3
4 5 6

First, direct drawing function
There are two direct plotting functions, fplot and Ezplot
1.fplot
The invocation format of the Fplot command is mainly:
(1) Fplot (fun,lims,str,tol): Direct drawing of Function Y=fun (x). Wherein, the lims is a vector, if the lims contains only two elements of the x-axis range: [Xmin,xmax]. If the lims contains four elements, the first two elements represent the range of the x-axis: [Xmin,xmax], and the last two elements represent the range of the y-axis: [Ymin,ymax]. STR can specify the Linetype and color of the graphic. The value of Tol is less than 1, which represents a relative error, and the default value is 0.002, or 0.2%.
>>fplot (@humps, [ -1,5])% draws a function within the range of [ -1,5] Humps
In the above command, the @humps represents referencing a function as a function handle. (C:Program filesmatlabr2009atoolboxmatlabdemoshumps.m).
(2) Fplot (fun,lims,n): Draw a graph of function fun with a minimum of n+1 points, where n is greater than or equal to 1.
>>fplot (' x^2 ', [-1 1])% draws a function within the [ -1,1] range y=x^2

2. Ezplot,ezplot3
The Ezplot command is a two-dimensional curve that draws the arguments of a symbolic expression and corresponds to each function value, and the EZPLOT3 command is used to draw three-dimensional curves.
(1) Curve drawing
Grammar:
Ezplot (f,[xmin,xmax],fig)% draw symbol expression F graphic
Description: F is the symbolic function to be drawn, [Xmin,xmax] is the argument range of the drawing, omitted when the default value is [ -2л,2л];fig is the specified graphics window, omit Shime think the current graphics window.
Cases:
>>y =sym (' -1/3*x^3+1/3*x^4 ')
y =
-1/3*x^3+1/3*x^4
>>ezplot (y)% draw symbol function y in [ -2л,2л] graphic
>>ezplot (y,[0,100])% drawing symbol function y in [0,100]
Another example
>>x=sym (' sin (t) ');
>>y=sym (' cos (t) ');
>>z=sym (' t ');
&GT;&GT;EZPLOT3 (X,y,z,[0,10*pi], ' animate ')% plot T three-dimensional curve in [0,10*PI] range
(2) Surface rendering
Such as
>>ezmesh (' sin (x) *exp (-t) ', ' cos (x) *exp (-t) ', ' X ', [0,2*pi]);
Ezmesh means easy to use the plotter mesh, so its call format is simple, drawing convenient.

(3) Other drawing commands
MATLAB also provides the more common drawing commands shown in the following table. Examples of these commands are drawing on string functions, as well as in symbolic expression drawings.
Example of command name meaning
Ezcontour Draw Contour Ezcontour (' X*sin (t) ', [ -4,4])
Ezcontourf draw with Fill color contour ezcontourf (' X*sin (t) ', [ -4,4])
Ezmesh painting three-dimensional Network Diagram Ezmesh (' Sin (x) *exp (-t) ', ' cos (x) *exp (-t) ', ' X ', [0,2*PI])
EZMESHC ezmeshc (' Sin (x) *t ', [-pi,pi])-three-dimensional line drawing with contour lines
Ezpolar Drawing Polar Chart ezpolar (' sin (t) ', [0,PI/2])
Ezsurf drawing three-dimensional surface graph Ezsurf (' x*sin (t) ', ' X*cos (t) ', ' t ', [0,10*PI])
EZSURFC drawing a three-dimensional surface graph with contour lines ezsurfc (' X*sin (t) ', ' X*cos (t) ', ' t ', [0,PI,0,2*PI])

Second, the grid method to draw three-dimensional surface

1. Generate three-dimensional data
In MATLAB, the Meshgrid function is used to produce a grid coordinate matrix in a planar area. The format is:
X=a:d1:b; Y=c:d2:d;
[X,y]=meshgrid (x, y);
After the statement executes, each row of the matrix x is a vector x, the number of rows equals the number of elements of the vector y, each column of the Matrix y is vector y, and the number of columns equals the number of elements of Vector x.
2. Functions for drawing three-dimensional surfaces
The surf function and the mesh function are called in the following format:
Mesh (X,Y,Z,C)
Surf (x,y,z,c)
In general, X, Y, Z is a matrix with the same number of dimensions. X, y is the grid coordinate matrix, z is the height matrix on the mesh point, and C is used to specify the color range at different heights.
Cases:
The surface graph is used to represent the function y=x^2+y^2.
Clf,x=-4:4;y=x; [X,y]=meshgrid (x, y);
z=x.^2+y.^2;
Surf (x, y, z); % or mesh (x, y, z)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.