MATLAB Learning Notes (10)--matlab graphics handle

Source: Internet
Author: User

(i) graphical objects and their handles

I. Graphical objects

Matlab graphic objects include:

1, matlab each of the specific graphics must include computer screen and graphics window two objects

Two, the graphic object handle

1. Definition

When you create each drawing object, Matlab assigns the object a uniquely determined value, which is referred to as a handle to a drawing object.

PS: (1) The computer screen handle defaults to 0.

(2) The handle value of the graphics window object is a positive integer and is displayed in the window title bar

(3) The handle of other drawing objects is a floating-point number.

2. Get a handle to an existing object

3, a demo

X=linspace (0,2*pi,+); y=sin (x); H0=plot (x, y,'R ')    Handle of the% curve object H1=gcf              % graphics window handle H2=GCA              % axis handle H3=findobj (GCA,'  Marker','x')            the handle of the curve on the% axis

The results of the operation are as follows:

H0 =  174.0016=     1=  173.0011=      0-by-1

(ii) Graphical object properties

First, property name and property value

Attribute name: Each property of each object is given a name, usually its English word, usually enclosed in a single apostrophe.

Attribute value: The value of each property name

Second, the operation of the attribute

1. Set function

When you create an object, you need to configure individual properties, otherwise it will be created with the default values.

(1) Call format

Set (handle, property name 1, property value 1, property name 2, property value 2, ...) )% where the handle indicates that the property in the%set of the object to be manipulated can be all default

(2) a demo.

x=0:p i/:2*pi;h=plot (x,sin (x)); Set (H,'Color','b','LineStyle  ',':','Marker','p  ');

2. Get function

We can also get the property value through get, then change

(1) Call format

v=get(handle, property name)%V is the property value that is returned if the property name is omitted, then all property values of the handle are returned.

(2) Demo

X=linspace (0.2*pi),y=sin (x), H= Plot (x,y), col=get(H, ' Color ');                % Gets the color of the curve v=Get(0,'screensize');         % get the flat screen resolution of the current window

Third, the public properties of the object

1. Children Properties:

The value is a vector that consists of a handle to all child objects of the object.

2. Parent Property:

The value is the handle to the parent object of the object.

3. Tag property:

The value is a string, as an identifier (alias) of the object

4. Type attribute:

Represents the type of the object (obviously it cannot be changed)

5. UserData Properties:

The value of this property is a matrix, and the default value is an empty matrix. It is common to store the more important data about a graphical object in this attribute, thereby achieving the effect of transmitting data.

General Practice: First use the Set function to add some additional data to a handle (a matrix), if you want to use such a matrix, and then call out with get.

6. Visible Property:

The value is on (default) or off. Decide whether to display on the screen. But not showing does not mean that it does not exist.

7. BUTTONDOWNFCN Properties:

The value is a string, usually an m file name or a MATLAB program. Graphical objects The tripod has a function area, and when you click the area, MATLAB automatically executes the program segment.

8. CREATFCN Properties:

The value is a string, usually an m file name or a MATLAB program. When the object is created, the program segment (the same constructor) is automatically self-

9. DELETEFCN Properties:

The value is a string, usually an m file name or a MATLAB program. The program segment (same destructor) is automatically self-propelled when the object is canceled

A demo:

x=0:p i/ -:2*Pi;y=sin (x); Z=cos (x);p lot (Y,'R', X,z,'g'); H1=Get(GCA,'Children'); %gets the two-curve handle vector H1 fork=1: Size (H1)if Get(H1 (k),'Color')==[0 1 0] %【0,1,0"indicates the green h1g=H1 (k); %gets the green line handle endendpause; %PauseSet(H1G,'LineStyle',':','Marker','P'); % to set the Green Line.

Results:

Press any key

(iii) Graphical object measurement creation

I. Graphics Window object

1. Definition

The graphics window is a very important type of graphic object in MATLAB. The output of all graphical images of MATLAB is done in the graphics window.

2. Call Format:

Handle variable = Figure(attribute name 1, attribute value 1, property name 2, attribute value 2); the% property name and property value can be defaulted, then the command follows the handle variable = Figure  or  figurefigure (window       handle)% set to the current window.                                   % If the window handle is written as an integer, you can use this handle to generate a new graphics window and define it as the current window. Close (Window handle)        % closes the graphics window close all;                      % off all graphics window CLF;                               % clears the contents of the current graphics window, but does not close the window.

3. Common Properties of Graphics window objects (except public properties)

(1) MenuBar property

The value is a figure (the default) or none, which controls whether the window has a menu bar.

If the property is None, then users can use the Uimenu function to add their own menu bar.

If the attribute is a figure, then the window remains the default menu bar, and you can use the Uimenu function to add a new menu item after the original default graphics Window menu.

(2) Name property

The value is a string, the default value is empty, as the title of the graphics serial port

(3) Numbertitle properties:

The value is on (the default) or off. Decide whether to prefix the title with "Figure NO.N:", where n is the ordinal of the graphics window, which is the handle value.

(4) Resize properties:

The value is on (default) or off. Determines whether the window's size can be changed with the mouse after the Window object is established

(5) Position property

(6) Units Properties:

The value of this property can be any of the following strings:

Pixel (pixels, default), normalized (relative units), inches (inches), centimeters (cm), and points (lb).

(7) Color property:

Values can be expressed in characters, or in ternary groups. The default value is ' K ', which is black.

(8) Pointer properties:

The values are arrow (default), Crosshair, watch, TOPL, TOPR, Botl, BOTR, Circle, Cross, Fleur, custom, and so on.

(9) for keyboard and mouse response properties:

Allows you to respond to such actions as keyboard and mouse keys.

Keypressfcn Keyboard Key Press the response
Windowbuttondownfcn mouse button Press the response
Windowbuttonmotionfcn Mouse Interference response
Windowbuttonupfcn mouse button Release response

4, a demo

X=linspace (0.2*PI, -); y=sin (x); HF=figure ('Color',[0,1,0],'Position',[1,1, the, -],'Name','Fuck','Numbertitle','off','MenuBar','None','KEYPRESSFCN','plot (x, y); axis ([0,2*pi,-1,1]);');

Results:

Second, the Axis object

MATLAB Learning Notes (10)--matlab graphics handle

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.