Graphics |
Querying Property Values
Use get
to query the current value of a property or of all the object's properties. For example, check the value of the current axes PlotBoxAspectRatio
property.
MATLAB lists the values of all properties, where practical. However, for properties containing data, MATLAB lists the dimensions only (for example, CurrentPoint
and ColorOrder)
.
AmbientLightColor = [1 1 1] Box = off CameraPosition = [0.5 0.5 2.23205] CameraPositionMode = auto CameraTarget = [0.5 0.5 0.5] CameraTargetMode = auto CameraUpVector = [0 1 0] CameraUpVectorMode = auto CameraViewAngle = [32.2042] CameraViewAngleMode = auto CLim: [0 1] CLimMode: auto Color: [0 0 0] CurrentPoint: [ 2x3 double] ColorOrder: [ 7x3 double].
.
. Visible = on
Querying Individual Properties
You can obtain the data from the property by getting that property individually.
get(gca,'ColorOrder') ans = 0 0 1.0000 0 0.5000 0 1.0000 0 0 0 0.7500 0.7500 0.7500 0 0.7500 0.7500 0.7500 0 0.2500 0.2500 0.2500
Returning a Structure
If you assign the output of get
to a variable, MATLAB creates a structure array whose field names are the object property names and whose field values are the current values of the named property.
For example, if you plot some data, x
and y
,
and get the properties of the line object created by plot
,
you can access the values of the line properties using the field name. This call to the text
command places the string 'x and y data' at the first data point and colors the text to match the line color.
If x
and y
are matrices, plot
draws one line per column. To label the plot of the second column of data, reference that line.
Querying Groups of Properties
You can define a cell array of property names and conveniently use it to obtain the values for those properties. For example, suppose you want to query the values of the axes "camera mode" properties. First define the cell array.
camera_props(1) = {'CameraPositionMode'}; camera_props(2) = {'CameraTargetMode'}; camera_props(3) = {'CameraUpVectorMode'}; camera_props(4) = {'CameraViewAngleMode'};
Use this cell array as an argument to obtain the current values of these properties.
Setting Property Values | Factory-Defined Property Values |