Configure Model Style Elements Programmatically - MATLAB & Simulink (original) (raw)

Main Content

You can change the fonts, font sizes, and colors of a model diagram programmatically using the set_param function. For example, you can change the background color of the model diagram or the color of the blocks.

The model, library, or subsystem whose style elements you want to configure must be loaded. For information about how to load models, libraries, and subsystems, see Create, Load, Open, Save, and Close Models Programmatically.

For information on how to arrange, position, or resize model content, see Configure Model Layout Programmatically.

Change Font Style and Font Size

To change the font of text of a block, signal line, or annotation, change the value of the FontName parameter using the set_param function. For example, to change the font of a block with the handleh to Arial, use this command.

set_param(h,FontName="Arial")

You can use the same command to change the font of a signal line or an annotation with the handle h to Arial. For information about how to specify the block, signal line, or annotation you want to edit, see the set_param function documentation and Get Handles and Paths.

To change the font size, change the value of the FontSize parameter instead. For example, to change the font size of a block with the handleh to 15, use this command.

set_param(h,FontSize="15")

You can use the same command to change the font size of a signal line or an annotation with the handle h to 15.

Change Color

Using the set_param function, you can change the background color of model diagrams, the background and foreground colors of blocks, and the background and text color of annotations. The color of a signal line is the same as the color of the block to whose output port the signal line connects.

This is the basic syntax for changing colors.

set_param(obj,Name=color)

obj is the handle or filename of the model, the handle or path of the block, or the handle of the annotation whose color you want to change. For information about how to get handles and paths, see Get Handles and Paths.Name is the programmatic name of the parameter that controls the color you want to change. color is the new color.

Specify the color as an RGB vector in the form "[r,g,b]", wherer, g, and b are the red, green, and blue components of the color normalized to the range 0.0 to1.0. Alternatively, specify the color as one of these values.

Color Value
Constant block with the foreground color automatic "automatic"
Constant block with the foreground color black "black"
Constant block with the foreground color white "white"
Constant block with the foreground color gray "gray"
Constant block with the foreground color red "red"
Constant block with the foreground color blue "blue"
Constant block with the foreground color green "green"
Constant block with the foreground color yellow "yellow"
Constant block with the foreground color orange "orange"
Constant block with the foreground color magenta "magenta"
Constant block with the foreground color light blue "lightBlue"
Constant block with the foreground color cyan "cyan"
Constant block with the foreground color dark green "darkGreen"

The table shows examples of how to change the colors of a model diagram, block, and annotation.

Action Example
Change the background color of a model diagram.Model with the background color set to cyan Change the background color of the model diagram in a model with the handle h to cyan.set_param(h,ScreenColor="cyan");
Change the background color of a block.Block with the a brown background Change the background color of the block with the handleh to brown.set_param(h,BackgroundColor="[0.25 0 0]")
Change the foreground color of a block.Block with the a red foreground Change the foreground color of the block with the handleh to red.set_param(h,ForegroundColor="red")
Change the background color of an annotation.Annotation with a green background Change the background color of the annotation with the handleh to green.set_param(h,BackgroundColor="green")
Change the text color of an annotation. Annotation with green text Change the text color of the annotation with the handleh to green.set_param(h,ForegroundColor="green")

See Also

get_param | set_param

Topics