Default Property Values - MATLAB & Simulink (original) (raw)

Predefined Values for Properties

Nearly all graphics object properties have predefined values. Predefined values originate from two possible sources:

Users can create default values for an object property, which take precedence over the factory-defined values. Objects use default values when:

Specify Default Values

Define a default property value using a character vector with these three parts:

'default' ObjectType PropertyName

A character vector that specified the default line LineWidth would be:

Use this character vector to specify the default value. For example, to specify a default value of 2 points for the line LineWidth property, use the statement:

set(groot,'defaultLineLineWidth',2)

The character vector defaultLineLineWidth identifies the property as a line property. To specify the figure color, use defaultFigureColor.

set(groot,'defaultFigureColor','b')

Where in Hierarchy to Define Default

In general, you should define a default value on the root level so that all subsequent plotting functions use those defaults. Specify the root in set andget statements using the groot function, which returns the handle to the root.

You can define default property values on three levels:

For example, specify a default figure color only on the root level.

set(groot,'defaultFigureColor','b')

List Default Values

Use get to determine what default values are currently set on any given object level:

returns all default values set in your current MATLAB session.

Set Properties to the Current Default

Specifying a property value of 'default' sets the property to the first encountered default value defined for that property. For example, these statements result in a green surface EdgeColor:

set(groot,'defaultSurfaceEdgeColor','k') h = surface(peaks); set(gcf,'defaultSurfaceEdgeColor','g') set(h,'EdgeColor','default')

Because a default value for surface EdgeColor exists on the figure level, MATLAB encounters this value first and uses it instead of the defaultEdgeColor defined on the root.

Remove Default Values

Specifying a property value of 'remove' gets rid of user-defined default values. The statement

set(groot,'defaultSurfaceEdgeColor','remove')

removes the definition of the default surface EdgeColor from the root.

Set Properties to Factory-Defined Values

Specifying a property value of 'factory' sets the property to its factory-defined value. For example, these statements set the EdgeColor of surface h to black (its factory setting), regardless of what default values you have defined:

set(gcf,'defaultSurfaceEdgeColor','g') h = surface(peaks); set(h,'EdgeColor','factory')

List Factory-Defined Property Values

You can list factory values:

Reserved Words

Setting a property value to default, remove, orfactory produces the effects described in the previous sections. To set a property to one of these words (for example, a text String property set to the word default), precede the word with the backslash character:

h = text('String','\default');