Set graphics object properties
set(H,Name,Value)
set(H,NameArray,ValueArray)
set(H,S)
s = set(H)
values = set(H,Name)
Do not use theset
function on Java™ objects as it will cause a memory leak. For more information, seeAccess Public and Private Data.
set(H,Name,Value)
specifies a value for the propertyName
on the object identified byH
. Use single quotes around the property name, for example,set(H,'Color','red')
. IfH
is a vector of objects, thenset
sets the property for all the objects. IfH
is empty (that is,[]
),set
does nothing, but does not return an error or warning.
set(H,NameArray,ValueArray)
specifies multiple property values using the cell arraysNameArray
andValueArray
. To setn
property values on each ofm
graphics objects, specifyValueArray
as anm
-by-n
cell array, wherem = length(H)
andn
is equal to the number of property names contained inNameArray
.
set(H,S)
specifies multiple property values usingS
, whereS
is a structure whose field names are the object property names and whose field values are the corresponding property values. MATLAB®ignores empty structures.
s = set(H)
returns the user-settable properties and possible values for the object identified byH
.s
is a structure array whose field names are the object's property names and whose field values are the possible values of the corresponding properties. If you do not specify an output argument, the MATLAB software displays the information on the screen.H
must be a single object.
values = set(H,Name)
returns the possible values for the specified property. If the possible values are character vectors,set
returns each in a cell of the cell arrayvalues
. For other properties,set
returns a statement indicating thatName
does not have a fixed set of property values. If you do not specify an output argument, MATLAB displays the information on the screen.H
must be a single object.
关于属性的更多信息你可以设置,see the property pages for each object, for example,Figure Properties,Axes Properties,Line Properties,Text Properties, and so on.
Plot a line and return the chart line object asp
. Set theColor
property of the line to'red'
.
p = plot(1:10); set(p,'Color','red')
Create a plot with four lines using random data and return the four chart line objects asP
. Set theColor
property for all of the lines to'red'
.
P = plot(rand(4)); set(P,'Color','red')
设置的值LineStyle
property for four chart line objects each to a different value. Transpose the value of the cell array so that it has the proper shape.
P = plot(rand(4)); NameArray = {'LineStyle'}; ValueArray = {“- - -”,'--',':','-.'}'; set(P,NameArray,ValueArray)
Set the values of theMarker
andTag
properties on three different stem series objects to different values. Each row of the value cell array corresponds to an object inh
and contains two values, one for theMarker
property and one for theTag
property.
x = 0:30; y = [1.5*cos(x); 4*exp(-.1*x).*cos(x); exp(.05*x).*cos(x)]'; S = stem(x,y); NameArray = {'Marker','Tag'}; ValueArray = {'o','Decaying Exponential';...'square','Growing Exponential';...'*','Steady State'}; set(S,NameArray,ValueArray)
You can use any combination of property name/property value pairs, structure arrays, and cell arrays in one call toset
.
Note that if you are setting both theFontSize
and theFontUnits
properties in one function call, you must set theFontUnits
property first so that the MATLAB software can correctly interpret the specifiedFontSize
. The same applies to figure and axes units — always set theUnits
property before setting properties whose values you want to be interpreted in those units. For example,
f = figure('Units','characters','Position',[30 30 120 35]);