set - Set graphics object properties - MATLAB (original) (raw)

Set graphics object properties

Syntax

Description

set([h](#mw%5F1df09703-caf2-4c3e-be8e-fe59f77e1f61),[Name,Value](#mw%5Fb034a773-89fc-43a4-b937-9787642e0d6b)) sets properties for the specified graphics object h using one or more name-value arguments. If h is a vector of objects, thenset sets the properties for all the objects inh. If h is empty ([ ]), set does nothing and does not return an error or warning.

For more information about properties that you can set, see the property pages for each object, for example, Figure, Axes Properties, Line Properties, and Text Properties.

example

set([h](#mw%5F1df09703-caf2-4c3e-be8e-fe59f77e1f61),[defaultTypeProperty,defaultValue](#mw%5F3d900102-ddee-4ac7-9b00-1bacb3c83d97)) changes the default value of the specified property and object type for the specified graphics object h using one or more pairs of property names and values.defaultTypeProperty is the word default concatenated with the object type (for example, Figure) and the property name (for example, Color) in quotes. For example,set(groot,"defaultFigureColor","red") changes the default value of theColor property of Figure objects tored for the graphics root object, groot.

set([h](#mw%5F1df09703-caf2-4c3e-be8e-fe59f77e1f61),[NameArray](#mw%5Fec33a3c2-234f-4a72-8c8c-f6b3d89c49a9),[ValueArray](#mw%5F24edb6a9-d994-45ac-b380-876e97650279)) sets multiple properties for the specified graphics object h.

example

set([h](#mw%5F1df09703-caf2-4c3e-be8e-fe59f77e1f61),[a](#mw%5F5406e16a-31a0-4168-95d9-c467e4c33b98)) sets multiple properties using a, which is a structure whose field names are the object property names and whose field values are the corresponding property values. Ifa is empty, set does nothing and does not return an error or warning.

example

[s](#mw%5F7029248a-ea4c-418a-8614-69b38819a757) = set([h](#mw%5F1df09703-caf2-4c3e-be8e-fe59f77e1f61)) returns the user-settable properties and possible values for the specified graphics objecth. h must be a single object. This syntax does not change the properties of h.

If s is not specified, set displays the user-settable properties and possible values in the Command Window.

example

[v](#mw%5Fa8567cc6-3720-470f-b72b-ac9ee82789dc) = set([h](#mw%5F1df09703-caf2-4c3e-be8e-fe59f77e1f61),[propertyName](#mw%5F9814c468-ef94-4f14-be4a-1ae5e6a9e3dd)) returns the possible values for the specified property. If the possible values are character vectors or strings, set returns a cell array containing the values. For other properties that do not have a fixed set of values, set returns an empty cell array. h must be a single object. This syntax does not change the properties of h.

If v is not specified, set displays the possible values in the Command Window.

Examples

collapse all

Create a line plot and return the Line object as p. Set the Color property of the line to "red".

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

Figure contains an axes object. The axes object contains an object of type line.

Create a figure with three buttons and put them into the array btns. Set the FontColor property of all the buttons to "red".

fig = uifigure; btn1 = uibutton(fig,"Position",[100 100 100 20]); btn2 = uibutton(fig,"Position",[100 75 100 20]); btn3 = uibutton(fig,"Position",[100 50 100 20]); btns = [btn1 btn2 btn3]; set(btns,"FontColor","red")

Figure contains objects of type uibutton.

Create a plot with four lines using random data, and return the four Line objects as p. Set the LineStyle property of each of the four Line objects to a different value. Transpose the list of LineStyle values from a row vector to a column vector to match the shape of p.

p = plot(rand(4)); NameArray = {'LineStyle'}; ValueArray = transpose({'-','--',':','-.'}); set(p,NameArray,ValueArray)

Figure contains an axes object. The axes object contains 4 objects of type line.

Plot a discrete data sequence and return the three Stem objects as st. Set the Marker and Tag properties of the three different Stem objects to different values. Each row of the value cell array corresponds to an object in st and contains two values, one for the Marker property and one for the Tag property.

x = 0:30; y = [1.5cos(x); 4exp(-.1*x).cos(x); exp(.05x).cos(x)]'; st = stem(x,y); NameArray = {'Marker','Tag'}; ValueArray = {'o','Decaying Exponential'; ... 'square','Growing Exponential'; ... '','Steady State'}; set(st,NameArray,ValueArray)

Figure contains an axes object. The axes object contains 3 objects of type stem.

Create a figure and return the user-settable properties and possible values for the figure.

fig = uifigure; s = set(fig);

Display the possible values for the Pointer property.

ans = 17×1 cell {'arrow' } {'ibeam' } {'crosshair'} {'watch' } {'topl' } {'topr' } {'botl' } {'botr' } {'circle' } {'cross' } {'fleur' } {'custom' } {'left' } {'top' } {'right' } {'bottom' } {'hand' }

Create a structure with Name, Color, and Pointer fields, and use the structure to set those properties for the figure.

a.Name = "My App"; a.Color = "red"; a.Pointer = "crosshair";

set(fig,a)

Input Arguments

collapse all

Graphics objects, specified as a single object or a vector of objects.

Property and value pairs, specified as Name1=Value1,...,NameN=ValueN, whereName is the property name and Value is the corresponding value.

Each type of object supports a different set of properties. For a full list of properties and descriptions for each type, see the associated object property page (for example, Figure, Axes Properties, Line Properties, and Text Properties).

To set property values, specify the name followed by an equal sign (=) and the corresponding value. For example,set(h,Color="red").

Before R2021a, use commas to separate each name and value, and enclose Name in quotes. For example,set(h,"Color","red").

To set a property to its default value, specify the property value as the worddefault in quotes. For example,set(h,"Color","default").

For more information about setting default values, see Default Property Values.

Default property and value pairs, specified asdefaultTypeProperty1=defaultValue1,...,defaultTypePropertyN=defaultValueN, where defaultTypeProperty is the word default concatenated with the object type (for example, Figure) and the property name (for example, Color), anddefaultValue is the corresponding default value.

To change default property values, specify defaultTypeProperty followed by an equal sign (=) and the corresponding default value. For example, set(h,defaultFigureColor="red").

Before R2021a, use commas to separate each name and value, and enclose Name in quotes. For example,set(h,"defaultFigureColor","red").

To remove the default value for a property, specify the property value as the wordremove in quotes. For example,set(h,"defaultFigureColor","remove").

For more information about setting default values, see Default Property Values.

Property names, specified as a cell array containing one or more property names.

Property values, specified as an _m_-by-n cell array, where m is the number of elements in h and n is the number of property names contained inNameArray.

Object property names and values, specified as a structure whose field names are the object property names and whose field values are the corresponding property values.

Property name, specified as a string scalar or character vector.

Output Arguments

collapse all

Property names and their values, returned as a structure. In the structure, the field names are the object property names, and the field values are the possible values of the corresponding properties.

Possible property values, returned as a cell array. If the possible values are character vectors or strings, set returns a cell array containing the values. For other properties that do not have a fixed set of values,set returns an empty cell array.

Tips

Version History

Introduced before R2006a