MATLAB graphic interface design (I)

Source: Internet
Author: User
Tags control characters
Reference https://www.cnblogs.com/BlueMountain-HaggenDazs/p/4307777.html I. Graphic handle1. Definition

When creating a graphic object, Matlab assigns a unique and definite value to the object, which is called a graphical object handle.

PS: (1) the default screen handle of the computer is 0.

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

(3) the handle of other graphic objects is a floating point number.

2. Get the handle of an existing object

Enter the code result directly, for example, (1) GCF:

(2) GCA:

(3) GCO:

Sample Code:

X = linspace (0, 2 * Pi, 30); y = sin (x); h0 = plot (X, Y, 'R ') % curve object handle H1 = GCF % graphic window handle H2 = GCA % coordinate axis handle h3 = findobj (GCA, 'marker', 'x') % coordinate axis curve handle

Output the handle of each object.

3. Graphic object attributes (1) Set Function

Set (handle, attribute name 1, attribute value 1, attribute name 2, attribute value 2 ,......)
The handle specifies the object to be operated. The properties in the set can all be default.

(2) Get Function

V = get (handle, attribute name)
V is the returned property value. If the attribute name is omitted, all property values of the handle are returned.

X = linspace (0.2 * Pi, 20); y = sin (x); H = plot (x, y); % assign the image handle to hcol = get (H, 'color'); % obtain the curve color v = get (0, 'screensize'); % obtain the flat screen resolution of the current window
4. Public attributes of Objects

(1) Children attributes:

The value is a vector composed of handles of all sub-objects of the object.

(2) parent attributes:

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

(3) tag attributes:

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

(4) type attribute:

Indicates the object type (obviously it cannot be changed)

(5) userdata attributes:

The value of this attribute is a matrix. The default value is an empty matrix. Generally, important data related to a graphic object is stored in this attribute to transfer data.

General Practice: first use the set function to add some additional data (a matrix) to a handle. If you want to use such a matrix, use get to call it.

(6) Visible attributes:

The value can be on (default) or off. Determines whether to display on the screen. However, if it is not displayed, it does not mean that it does not exist.

(7) buttondownfcn attributes:

The value is a string, usually a M file name or a MATLAB program. The graphic object has a function area. When you click the area, Matlab automatically runs the program segment.

(8) attributes of creatfcn:

The value is a string, usually a M file name or a MATLAB program. This program segment is automatically created when this object is created (same as the constructor)

(9) deletefcn attributes:

The value is a string, usually a M file name or a MATLAB program. This program segment is automatically used when this object is canceled (same as the destructor)

5. Example
X = 0: PI/50: 2 * PI; y = sin (x); Z = cos (x); plot (X, Y, 'R', X, Z, 'G'); H1 = get (GCA, 'Children '); % get two curve handle vector h1for k = 1: size (H1) if get (H1 (K ), 'color') = [0 1 0] % [0, 1, 0] indicates green h1g = h1 (k); % get the green line handle endendpause; % pause set (h1g, 'linestyle', ':', 'marker', 'P'); % set the Green Line.
Ii. Create a graphic object 1. Window object
Handle variable = figure (attribute name 1, attribute value 1, attribute name 2, attribute value 2); % attribute name and attribute value can be default, the command below handle variable = figure or figurefigure (window handle) % is set to the current window. Close (window handle) % Close drawing window close all; % Close all drawing windows CLF; % clear the content of the current drawing window, but do not close the window.

(1) menubar attributes

The value is figure (default value) or none, which is used to control whether a menu bar exists in the window.

If the attribute is none, you can use the uimenu function to add your own menu bar.

If the attribute is figure, the window will retain the default menu bar. In this case, you can use the uimenu function to add a new menu item after the original default graphic Window menu.

(2) name attribute

The value is a string. The default value is null and serves as the title of the graphic serial port.

(3) numbertitle attributes:

The value can be on (default) or off. Determines whether to use "Figure No. N:" As the title prefix. Here N is the serial number of the graphic window, that is, the handle value.

(4) resize attributes:

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

(5) Position attribute

(6) units attributes:

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

Pixel (pixel, default), normalized (relative unit), inches (INCHES), centimeters (cm), and points (lbs ).

(7) color attributes:

The value can be represented by characters or triplet. The default value is 'k', Which is black.

(8) pointer attributes:

Optional values: Arrow (default value), crosshair, watch, topl, topr, botl, botr, circle, cross, Fleur, and custom.

(9) keyboard and mouse response properties:

Allows you to respond to keyboard and mouse keys.

2. Axis object
Handle variable = axes (attribute name 1, attribute value 1, attribute name 2, attribute value 2 ,......); % Call the axes function to create an axis in the current graph window using the brake attribute and assign the handle to the handle variable. Axes or handle variable = axes % use the axes function to create the default axis axes (axis handle) % call the axes function to set it to the current axis, the graphic window where the axis is located automatically becomes the current graphic window.

(1) Box attributes:

The value is on or off (default ). It determines whether the coordinate axis has a border.

(2) gridlinestyle attributes:

Optional values: '(default value),'-','-. ',' -- ', and 'none '. This attribute defines the type of the gridline.

(3) Position attribute:

This attribute is a vector composed of four elements, in the form of [N1, N2, N3, N4]. This vector determines a rectangular area in the graphic window, where the coordinate axes are located.

(N1, N2) is the coordinate in the lower left corner, and (N3, N4) is the width and height of the rectangle. The Unit is determined by the units attribute.

(4) unit attributes:

The values are normalized (relative unit, default value), inches (INCHES), centimeters (cm), and points (lbs ).

(5) Title attributes:

The value of this attribute is the handle of the title Text object of the coordinate axis. You can use this attribute to operate the title Text object of the coordinate axis.

 

ans=get(gca,‘Title‘);set(ans,‘Color‘,‘r‘);

(6) xlabel, ylabel, and zlabel attributes:

The values are the handles of X, Y, and Z axes. Its operation and title attributes are the same.

 

ans=get(gca,‘XLabel‘);set(ans,‘String‘,‘Values of X axis‘);

(7) xlim, ylim, and zlim attributes:

All values are numerical vectors with two elements. The three attributes define the upper and lower limits of the coordinate axes respectively. The default value is [0, 1].

(8) XScale, yscale, and zscale attributes:

The values are 'linear '(default value) or 'log'. These attributes define the scale type of each coordinate axis.

(9) view attributes:

The value is a numerical vector of two elements and defines the viewpoint direction.

3. Curve object
Handle variable = line (X, Y, Z, attribute name 1, attribute value 1, attribute name 2, attribute value 2 ,......); % X, y, and z are 3D coordinates.

(1) color attributes:

The value of this attribute is a character or RGB value of a color. Define the curve color.

(2) linestyle attributes:

Define Linearity

(3) linewidth attributes:

Defines the line width. The default value is 0.5 lbs.

(4) attributes of marker:

Defines the data point markup symbol. The default value is none.

(5) attributes of markersize:

Defines the size of the data point markup symbol. The default value is 6 lbs.

(6) xdata, ydata, and zdata attributes:

The values are both numerical vectors or matrices, representing the three coordinate axes of the curve object respectively.

4. Text object
Handle variable = text (X, Y, Z, 'descriptive text', attribute name 1, attribute value 1, attribute name 2, attribute value 2 ,......); % The description text can use latex to control characters

(1) color attributes:

Defines the color of a text object.

(2) string attributes:

The value is a string or a string matrix that records the content of the text annotation.

(3) interpreter attributes:

The value is latex (default value) or none. This attribute controls how the text content is interpreted, that is, latex or ASCII,

(4) fontsize attributes:

Defines the size of a text object. The default value is 10 lbs.

(5) Rotation attributes:

The value is a numeric value. The default value is 0. defines the Rotation Angle of the Text object. The positive value indicates clockwise rotation.

 

MATLAB graphic interface design (I)

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.