文件

访问属性值

对象属性和点表示法

图形函数返回函数创建的对象或对象。例如:

H= plot(1:10);

Hrefers to the line drawn in the graph of the values 1 through 10.

Dot notation是在R2014B中启动的访问对象属性的新语法。此语法使用对象变量和与点连接的区分敏感的属性名称()形成对象点属性名称表示法:

目的。propertyname.

如果nonscalar对象变量,使用索引到refer to a single object:

目的(n).PropertyName

标量对象变量

IfH是由此创建的线阴谋功能,表达式H。颜色是这个特定行的价值颜色property:

H。颜色
ans = 0 0.4470 0.7410

如果将颜色值分配给变量:

c = h.Color;

The variableCis a double.

谁是
Name Size Bytes Class c 1x3 24 double h 1x1 112 matlab.graphics.chart.primitive.Line

You can change the value of this line’s颜色具有作业声明的财产:

H。颜色= [0 0 1];

Use dot notation property references in expressions:

meanY = mean(h.YData);

或更改属性值:

H.LineWidth = H.LineWidth + 0.5;

Reference other objects contained in properties with multiple dot references:

H。Annotation.LegendInformation.IconDisplayStyle
ans = on

Set the properties of objects contained in properties:

AX = GCA;ax.title.fontweight =.'普通的';

nonscalar对象变量

Graphics functions can return an array of objects. For example:

y =兰特(5);h = plot(y);尺寸(h)
ans = 5 1

访问代表第一列的行y使用数组索引:

h(1).linestyle =' - ';

使用function to set theLINESTYLE.在阵列中的所有行:

放(H那'LineStyle'' - '的)

Appending Data to Property Values

使用点表示法,您可以使用“结束”索引来将数据追加到包含数据阵列的属性,例如行xdata.andydata.。For example, this code updates the linexdata.andydata.到gether to grow the line. You must ensure the size of line’s x- and y-data are the same before rendering with the call todrawnor returning to the MATLAB®迅速的。

H= plot(1:10);为了k = 1:5 h.xdata(end + 1)= h.xdata(end)+ k;H.YDATA(末端+ 1)= H.YDATA(END)+ K;drawn结尾

图形对象变量是句柄

图形功能返回的对象变量是把握。处理是对实际对象的引用。在复制时以及删除对象时,在特定方式中表现的对象变量在删除时。

复制对象变量

For example, create a graph with one line:

H= plot(1:10);

现在将对象变量复制到另一个变量,并使用新对象变量设置属性值:

H2= h; h2.Color = [1,0,0]

Assigning the object variableHH2创建句柄的副本,但不是变量引用的对象。的价值颜色property accessed from variableHis the same as that accessed from variableH2

H。颜色
ans = 1 0 0

HandH2refer to the same object. Copying a handle object variable does not copy the object.

删除对象变量

There are now two object variables in the workspace that refer to the same line.

谁是
名称大小字节类H 1x1 112 MATLAB.Graphics.chart.PRimitive.line H2 1x1 112 MATLAB.Graphic.Chart.primitive.line

现在关闭包含线图的图形:

关闭GCF.

行对象不再存在,但仍然存在引用该行的对象变量:

谁是
名称大小字节类H 1x1 112 MATLAB.Graphics.chart.PRimitive.line H2 1x1 112 MATLAB.Graphic.Chart.primitive.line

但是,对象变量不再有效:

H。颜色
Invalid or deleted object.
h2.color =.'blue'
Invalid or deleted object.

To remove the invalid object variables, useClear

ClearHH2

列出对象属性

要查看对象包含的属性,请使用get功能:

得到(h)

MATLAB返回对象属性的列表及其当前值:

AlignVertexCenters: 'off' Annotation: [1x1 matlab.graphics.eventdata.Annotation] BeingDeleted: 'off' BusyAction: 'queue' ButtonDownFcn: '' Children: [] Clipping: 'on' Color: [0 0.4470 0.7410] ... LineStyle: '-' LineWidth: 0.5000 Marker: 'none' ...

您可以使用枚举集可能值查看属性的值功能:

放(H那'LineStyle'的)
'-' '--' ':' '-.' 'none'

To display all settable properties including possible values for properties with an enumerated set of values, usewith the object variable:

放(H的)

使用设置和获取修改属性

您还可以使用此访问和修改属性andgetfunctions.

The basic syntax for setting the value of a property on an existing object is:

放(目的那'propertyname.',NewPropertyValue)

要查询特定对象属性的当前值,请使用表单的语句:

return_value = get(目的那'propertyname.');

属性名称始终是字符向量。您可以使用单引号或一个是字符向量的变量。属性值取决于特定属性。

Multi Object/Property Operations

If the object argument is an array, MATLAB sets the specified value on all identified objects. For example:

y =兰特(5);h = plot(y);

将所有线设置为红色:

放(H那'Color''红色的'的)

要在多个对象上设置相同的属性,请使用结构或单元格数组指定属性名称和属性值。例如,定义一个结构以适当地设置轴属性以显示特定的图形:

view1.CameraViewAngleMode = 'manual'; view1.DataAspectRatio = [1 1 1]; view1.Projection = 'Perspective';

To set these values on the current axes, type:

放(gca,view1)

查询多个属性

您可以定义属性名称的单元格数组,并使用它来获取这些属性的值。例如,假设您要查询轴“摄像机模式”属性的值。首先,定义单元格数组:

Cammodes = {'camerapositionMode''cameratargetmode'......'cameraupvectormode''cameraviewanglemode'};

使用此单元格数组作为参数以获取这些属性的当前值:

获得(GCA,Cammodes)
ans ='auto''auto''auto''auto'