| Contents | Index |
| On this page… |
|---|
The Initialization pane allows you to enter MATLAB commands that initialize the masked subsystem.

When you open a model, initialization commands execute for masked blocks that are visible because they reside at the top level of the model or in an open subsystem and that meet either of the following conditions:
The masked block has icon drawing commands.
The masked subsystem is from a library and has the Allow library block to modify its contents parameter enabled.
A simple masked block that has initialization commands but no icon drawing commands does not execute the initialization commands when you open the model.
Initialization commands for masked blocks that are not initially visible execute when you open the subsystem or model that contains the blocks.
When you load a model into memory without displaying the model graphically, no initialization commands initially run for any masked blocks. See Loading a Model and load_system for information about loading a model without displaying it.
Initialization commands for all masked blocks in a model that have drawing commands run when you:
Update the diagram
Start simulation
Start code generation
Initialization commands for an individual masked block run when you:
Change any of the parameters that define the mask, such as MaskDisplay and MaskInitialization, by using the Mask Editor or set_param.
Change the appearance of the masked block, for example by resizing or rotating the block.
Change the value of a mask parameter by using the block dialog or set_param.
Copy the masked block within the same model or between different models.
The Initialization pane contains the controls described in this section.
The Dialog variables list displays the names of the variables associated with the subsystem's mask parameters, which are defined in the Parameters pane. You can copy the name of a parameter from this list and paste it into the adjacent Initialization commands field, using the Simulink keyboard copy and paste commands. You can also use the list to change the names of mask parameter variables. To change a name, double-click the name in the list. An edit field containing the existing name appears. Edit the existing name and click Enter or click outside the edit field to confirm your changes.
Enter the initialization commands in this field. You can enter any valid MATLAB expression, consisting of MATLAB functions and scripts, operators, and variables defined in the mask workspace. Initialization commands run in the mask workspace, not the base workspace. Terminate initialization commands with a semicolon to avoid echoing results to the MATLAB Command Window.
This check box is enabled only if the masked subsystem resides in a library. Checking this option allows the block's initialization code to modify the contents of the masked subsystem by adding or deleting blocks and setting the parameters of those blocks. Otherwise, an error is generated when a masked library block tries to modify its contents in any way. To set this option at the MATLAB prompt, select the self-modifying block and enter the following command.
set_param(gcb, 'MaskSelfModifiable', 'on');
Then save the block.
Mask initialization commands must observe the following rules:
Do not use initialization code to create mask dialogs whose appearance or control settings change depending on changes made to other control settings. Instead, use the mask callbacks provided specifically for this purpose.
Avoid prefacing variable names in initialization commands with L_ and M_ to prevent undesirable results. These specific prefixes are reserved for use with internal variable names.
Avoid using set_param commands to set parameters of blocks residing in masked subsystems that reside in the masked subsystem being initialized. See Setting Nested Masked Block Parameters for details.
![]() | Parameters Pane | Documentation Pane | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |