Documentation

set

Set graphics object properties

Syntax

set(H,Name,Value)
set(H,NameArray,ValueArray)
set(H,S)
s = set(H)
values = set(H,Name)

Description

Note

Do not use thesetfunction 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 propertyNameon the object identified byH. Use single quotes around the property name, for example,set(H,'Color','red'). IfHis a vector of objects, thensetsets the property for all the objects. IfHis empty (that is,[]),setdoes nothing, but does not return an error or warning.

set(H,NameArray,ValueArray)specifies multiple property values using the cell arraysNameArrayandValueArray. To setnproperty values on each ofmgraphics objects, specifyValueArrayas anm-by-ncell array, wherem = length(H)andnis equal to the number of property names contained inNameArray.

set(H,S)specifies multiple property values usingS, whereSis 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.sis 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.Hmust be a single object.

values = set(H,Name)returns the possible values for the specified property. If the possible values are character vectors,setreturns each in a cell of the cell arrayvalues. For other properties,setreturns a statement indicating thatNamedoes not have a fixed set of property values. If you do not specify an output argument, MATLAB displays the information on the screen.Hmust be a single object.

Note

关于属性的更多信息你可以设置,see the property pages for each object, for example,Figure Properties,Axes Properties,Line Properties,Text Properties, and so on.

Examples

Change Color of Specific Line

Plot a line and return the chart line object asp. Set theColorproperty of the line to'red'.

p = plot(1:10); set(p,'Color','red')

Change Color for Multiple Lines

Create a plot with four lines using random data and return the four chart line objects asP. Set theColorproperty for all of the lines to'red'.

P = plot(rand(4)); set(P,'Color','red')

Set Line Style to Different Value for Multiple Lines

设置的值LineStyleproperty 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 Different Values for Multiple Properties on Multiple Objects

Set the values of theMarkerandTagproperties on three different stem series objects to different values. Each row of the value cell array corresponds to an object inhand contains two values, one for theMarkerproperty and one for theTagproperty.

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)

Tips

You can use any combination of property name/property value pairs, structure arrays, and cell arrays in one call toset.

Setting Property Units

Note that if you are setting both theFontSizeand theFontUnitsproperties in one function call, you must set theFontUnitsproperty first so that the MATLAB software can correctly interpret the specifiedFontSize. The same applies to figure and axes units — always set theUnitsproperty before setting properties whose values you want to be interpreted in those units. For example,

f = figure('Units','characters','Position',[30 30 120 35]);

Introduced before R2006a

Was this topic helpful?