Skip to Main Content Skip to Search
Product Documentation

Organizing Checks and Folders Within a Customization File

Customization File Overview

The sl_customization.m file contains a set of functions for registering and defining custom checks, tasks, and groups. To set up the sl_customization.m file, follow the guidelines in this table.

FunctionDescriptionRequired or Optional
sl_customization()Registers custom checks, tasks, folders, and callbacks with the Simulink customization manager at startup (see Registering Checks and Process Callbacks).Required for all customizations to the Model Advisor.
One or more check definitionsDefines all custom checks (see Defining Custom Checks).Required for custom checks and to add custom checks to the By Product folder.
One or more task definitionsDefines all custom tasks (see Defining Custom Tasks).Required to add custom checks to the Model Advisor, except when adding the checks to the By Product folder. Write one task for each check that you add to the Model Advisor.
One or more groupsDefines all custom groups (see Defining Custom Tasks).Required to add custom tasks to new folders in the Model Advisor, except when adding a new subfolder to the By Product folder. Write one group definition for each new folder.
One process callback functionSpecifies actions that Simulink performs at startup and post-execution time (see Defining Startup and Post-Execution Actions Using Process Callback Functions).Optional.

Register Tasks and Folders

Create sl_customization Function

To add tasks and folders to the Model Advisor, create the sl_customization.m file on your MATLAB path. Then create the sl_customization() function in the sl_customization.m file on your MATLAB path.

The sl_customization function accepts one argument, a customization manager object, as in this example:

function sl_customization(cm)

The customization manager object includes methods for registering custom checks, tasks, folders, and process callbacks. Use these methods to register customizations specific to your application, as described in the sections that follow.

Registering Tasks and Folders

The customization manager provides the following methods for registering custom tasks and folders:

Model Advisor Code Example: Registering Custom Tasks and Folders.  The following code example registers custom tasks and folders:

function sl_customization(cm)

% register custom factory group
cm.addModelAdvisorTaskFcn(@defineModelAdvisorTasks);

% register custom tasks.
cm.addModelAdvisorTaskAdvisorFcn(@defineTaskAdvisor);

Defining Custom Tasks

Adding a Check to Custom or Multiple Folders Using Tasks

You can use custom tasks for adding checks to the Model Advisor, either in multiple folders or in a single, custom folder. You define custom tasks in one or more functions that specify the properties of each instance of the ModelAdvisor.Task class. Define one instance of this class for each custom task that you want to add to the Model Advisor. Then register the custom task, as described in Register Tasks and Folders. The following sections describe how to define custom tasks.

To add a check to multiple folders or a single, custom folder:

  1. Create a check using the ModelAdvisor.Check class, as described in Defining Custom Checks.

  2. Register a task wrapper for the check, as described in Register Tasks and Folders.

  3. If you want to add the check to folders that are not already present, register and create the folders using the ModelAdvisor.Group class.

  4. Add a check to the task using the ModelAdvisor.Task.setCheck method.

  5. Add the task to each folder using the ModelAdvisor.Group.addTask method and the task ID.

Creating Custom Tasks Using MathWorks Checks

You can add MathWorks checks to your custom folders by defining the checks as custom tasks. When you add the checks as custom tasks, you identify checks by the check ID.

To find MathWorks check IDs:

  1. In the Model Advisor, select View > Source Tab.

  2. Navigate to the folder that contains the MathWorks check.

  3. In the right pane, click Source. The Model Advisor displays the Title, TitleID, and Source information for each check in the folder.

  4. Select and copy the TitleID of the check that you want to add as a task.

Displaying and Enabling Tasks

The Visible, Enable, and Value properties interact the same way for tasks as they do for checks (see Displaying and Enabling Checks).

Defining Where Tasks Appear

You can specify where the Model Advisor places tasks within the Model Advisor using the following guidelines:

Model Advisor Code Example: Task Definition Function

The following is an example of a task definition function. This function defines three tasks. The tasks are derived from the checks defined in Model Advisor Code Example: Check Definition Function.

For an example of placing these tasks into a custom group, see Model Advisor Code Example: Group Definition.

% Defines Model Advisor tasks and a custom folder
% Add checks to a custom folder using task definitions
function defineTaskAdvisor
mdladvRoot = ModelAdvisor.Root;

% Define task that uses Sample Check 1: Informational check
MAT1 = ModelAdvisor.Task('mathworks.example.task.configManagement');
MAT1.DisplayName = 'Informational check for model configuration management';
MAT1.Description = 'Display model configuration and checksum information.';
setCheck(MAT1, 'mathworks.example.configManagement');
mdladvRoot.register(MAT1);

% Define task that uses Sample Check 2: Basic Check with Pass/Fail Status
MAT2 = ModelAdvisor.Task('mathworks.example.task.unconnectedObjects');
MAT2.DisplayName = 'Check for unconnected objects';
setCheck(MAT2, 'mathworks.example.unconnectedObjects');
MAT2.Description = ['Identify unconnected lines, input ports, and output ' ...
                                      'ports in the model or subsystem.'];
mdladvRoot.register(MAT2);

% Define task that uses Sample Check 3: Check with Subresults and Actions
MAT3 = ModelAdvisor.Task('mathworks.example.task.optimizationSettings');
MAT3.DisplayName = 'Check safety-related optimization settings';
MAT3.Description = ['Check model configuration for optimization ' ...
                    'settings that can impact safety.'];
MAT3.setCheck('mathworks.example.optimizationSettings');
mdladvRoot.register(MAT3);

% Custom folder definition
MAG = ModelAdvisor.Group('mathworks.example.ExampleGroup');
MAG.DisplayName = 'My Group';
% Add tasks to My Group folder
addTask(MAG, MAT1);
addTask(MAG, MAT2);
addTask(MAG, MAT3);
% Add My Group folder to the Model Advisor under 'Model Advisor' (root)
mdladvRoot.publish(MAG);

Defining Custom Folders

About Custom Folders

Use folders to group checks in the Model Advisor by functionality or usage. You define custom folders in:

Define one instance of the group classes for each folder that you want to add to the Model Advisor. Then register the custom folder, as described in Register Tasks and Folders. The following sections describe how to define custom groups.

Adding Custom Folders

To add a custom folder:

  1. Create the folder using the ModelAdvisor.Group or ModelAdvisor.FactoryGroup classes.

  2. Add the folder to the Model Advisor, as described in Defining Custom Folders.

Defining Where Custom Folders Appear

You can specify the location of custom folders within the Model Advisor using the following guidelines:

Model Advisor Code Example: Group Definition

The following is an example of a group definition. The definition places the tasks defined in Model Advisor Code Example: Task Definition Function inside a folder called My Group under the Model Advisor root. The task definition function includes this group definition.

% Custom folder definition
MAG = ModelAdvisor.Group('mathworks.example.ExampleGroup');
MAG.DisplayName='My Group';
% Add tasks to My Group folder
MAG.addTask(MAT1);
MAG.addTask(MAT2);
MAG.addTask(MAT3);
% Add My Group folder to the Model Advisor under 'Model Advisor' (root)
mdladvRoot.publish(MAG);

The following is an example of a factory group definition function. The definition places the checks defined in Model Advisor Code Example: Check Definition Function into a folder called Demo Factory Group inside of the By Task folder.

function defineModelAdvisorTasks
mdladvRoot = ModelAdvisor.Root;

% --- sample factory group
rec = ModelAdvisor.FactoryGroup('com.mathworks.sample.factorygroup');
rec.DisplayName='Demo Factory Group';
rec.Description='Demo Factory Group';
rec.addCheck('mathworks.example.configManagement');
rec.addCheck('mathworks.example.unconnectedObjects');
rec.addCheck('mathworks.example.optimizationSettings');
mdladvRoot.publish(rec); % publish inside By Task

Demo and Code Example

The Simulink Verification and Validation software provides a demo that shows how to customize the Model Advisor by adding:

The demo also provides the source code of the sl_customization.m file that executes the customizations.

To run the demo:

  1. At the MATLAB command line, type slvnvdemo_mdladv.

  2. Follow the instructions in the model.

  


Related Products & Applications

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