|
|
|
| R2012a Documentation → Simulink Verification and Validation | |
Learn more about Simulink Verification and Validation |
|
| Contents | Index |
| On this page… |
|---|
Displaying and Enabling Checks Defining Where Custom Checks Appear Model Advisor Code Example: Check Definition Function Defining Check Input Parameters |
You can create a custom check to use in the Model Advisor. Creating custom checks provides you with the ability to specify which conditions and configuration settings the Model Advisor reviews.
You define custom checks in one or more functions that specify the properties of each instance of the ModelAdvisor.Check class. Define one instance of this class for each custom check that you want to add to the Model Advisor, and register the custom check as described in Registering Checks and Process Callbacks.
Tip You can add a check to multiple folders by creating a task. For more information, see Adding a Check to Custom or Multiple Folders Using Tasks. |
The following sections describe how to define custom checks.
When you define a Model Advisor check, it contains the information listed in the following table.
| Contents | Description | |
|---|---|---|
| Check ID (required) | Uniquely identifies the check. The Model Advisor uses this id to access the check. | |
| Handle to check callback function (required) | Function that specifies the contents of a check. | |
| Check name (recommended) | Creates a name for the check that the Model Advisor displays. | |
| Check properties (optional) | Creates a user interface with the check. When adding checks
as tasks, the Model Advisor uses the task properties instead of the
check properties, except for Visible and LicenseName.
For more information, see ModelAdvisor.Check and ModelAdvisor.Task.
| |
| Input Parameters (optional) | Adds input parameters that request input from the user. The Model Advisor uses the input to perform the check. | |
| Action (optional) | Adds automatic fixing action. | |
| Explore Result button (optional) | Adds the Explore Result button that the user clicks to open the Model Advisor Result Explorer. |
You can create a check and specify how it appears in the Model Advisor. You can define when to display a check, or whether a user can select or clear a check using the Visible, Enable, and Value properties of the ModelAdvisor.Check class.
Note When adding checks to the Model Advisor as tasks, specify these properties in the ModelAdvisor.Task class. If you specify the properties in both ModelAdvisor.Check and ModelAdvisor.Task, the ModelAdvisor.Task properties take precedence, except for the Visible and LicenseName properties. For more information, see ModelAdvisor.Task. |
Modify the behavior of the Visible, Enable, and Value properties in a process callback function (see Defining Startup and Post-Execution Actions Using Process Callback Functions). The following chart illustrates how these properties interact.

Specify where the Model Advisor places custom checks using the following guidelines:
To place a check in a new folder in the Model Advisor root, use the ModelAdvisor.Group class. See Defining Custom Tasks.
To place a check in a new folder in the By Task folder, use the ModelAdvisor.FactoryGroup class. See Defining Custom Tasks.
To place a check in the By Product folder, use the ModelAdvisor.Root.publish method.
The following is an example of a function that defines the custom checks associated with the callback functions described in Creating Callback Functions and Results. The check definition function returns a cell array of custom checks to be added to the Model Advisor.
The check definitions in the example use the tasks described in Defining Custom Tasks.
% Defines custom Model Advisor checks function defineModelAdvisorChecks % Sample check 1: Informational check rec = ModelAdvisor.Check('mathworks.example.configManagement'); rec.Title = 'Informational check for model configuration management'; setCallbackFcn(rec, @modelVersionChecksumCallbackUsingFT,'None','StyleOne'); rec.CallbackContext = 'PostCompile'; mdladvRoot = ModelAdvisor.Root; mdladvRoot.register(rec); % Sample check 2: Basic Check with Pass/Fail Status rec = ModelAdvisor.Check('mathworks.example.unconnectedObjects'); rec.Title = 'Check for unconnected objects'; setCallbackFcn(rec, @unconnectedObjectsCallbackUsingFT,'None','StyleOne'); mdladvRoot = ModelAdvisor.Root; mdladvRoot.register(rec); % Sample Check 3: Check with Subchecks and Actions rec = ModelAdvisor.Check('mathworks.example.optimizationSettings'); rec.Title = 'Check safety-related optimization settings'; setCallbackFcn(rec, @OptmizationSettingCallback,'None','StyleOne'); % Define an automatic fix action for this check modifyAction = ModelAdvisor.Action; setCallbackFcn(modifyAction, @modifyOptmizationSetting); modifyAction.Name = 'Modify Settings'; modifyAction.Description = ['Modify model configuration optimization' ... ' settings that can impact safety.']; modifyAction.Enable = true; setAction(rec, modifyAction); mdladvRoot = ModelAdvisor.Root; mdladvRoot.register(rec);
With input parameters, the check author can request input from the user for a Model Advisor check. Define input parameters using the ModelAdvisor.InputParameter class inside a custom check function (see Defining Custom Checks). You must define one instance of this class for each input parameter that you want to add to a Model Advisor check.
Specify the layout of input parameters in an input parameter definition. To place input parameters, use the following methods.
| Method | Description |
|---|---|
| ModelAdvisor.ChecksetInputParametersLayoutGrid | Specifies the size of the input parameter grid. |
| ModelAdvisor.InputParametersetRowSpan | Specifies the number of rows the parameter occupies in the Input Parameter layout grid. |
| ModelAdvisor.InputParametersetColSpan | Specifies the number of columns the parameter occupies in the Input Parameter layout grid. |
For information on using these methods, see the ModelAdvisor.Check and ModelAdvisor.InputParameter class documentation.
The following is an example of defining input parameters that you add to a custom check. You must include input parameter definitions inside a custom check definition (see Model Advisor Code Example: Check Definition Function). The following code, when included in a custom check definition, creates three input parameters.
rec = ModelAdvisor.Check('com.mathworks.sample.Check1'); rec.setInputParametersLayoutGrid([3 2]); % define input parameters inputParam1 = ModelAdvisor.InputParameter; inputParam1.Name = 'Skip font checks.'; inputParam1.Type = 'Bool'; inputParam1.Value = false; inputParam1.Description = 'sample tooltip'; inputParam1.setRowSpan([1 1]); inputParam1.setColSpan([1 1]); inputParam2 = ModelAdvisor.InputParameter; inputParam2.Name = 'Standard font size'; inputParam2.Value='12'; inputParam2.Type='String'; inputParam2.Description='sample tooltip'; inputParam2.setRowSpan([2 2]); inputParam2.setColSpan([1 1]); inputParam3 = ModelAdvisor.InputParameter; inputParam3.Name='Valid font'; inputParam3.Type='Combobox'; inputParam3.Description='sample tooltip'; inputParam3.Entries={'Arial', 'Arial Black'}; inputParam3.setRowSpan([2 2]); inputParam3.setColSpan([2 2]); rec.setInputParameters({inputParam1,inputParam2,inputParam3});
The Model Advisor displays these input parameters in the right pane, in an Input Parameters box.

A list view provides a way for users to fix check warnings and failures using the Model Advisor Result Explorer. Creating a list view allows you to :
Add the Explore Result button to the custom check in the Model Advisor window.
Provide the information to populate the Model Advisor Result Explorer.
For information on using the Model Advisor Results Explorer, see Batch-Fixing Warnings or Failures.
Define list views using the ModelAdvisor.ListViewParameter class inside a custom check function (see Defining Custom Checks). You must define one instance of this class for each list view that you want to add to a Model Advisor Result Explorer window.
The following is an example of defining list views. You must make the Explore Result button visible using the ModelAdvisor.Check.ListViewVisible property inside a custom check function, and include list view definitions inside a check callback function (see Detailed Check Callback Function).
The following code, when included in a check definition function, adds the Explore Result button to the check in the Model Advisor.
rec = ModelAdvisor.Check('com.mathworks.sample.Check1'); % add 'Explore Result' button rec.ListViewVisible = true;
The following code, when included in a check callback function, provides the information to populate the Model Advisor Result Explorer.
mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system); mdladvObj.setCheckResultStatus(true); % define list view parameters myLVParam = ModelAdvisor.ListViewParameter; myLVParam.Name = 'Invalid font blocks'; % the name appeared at pull down filter myLVParam.Data = get_param(searchResult,'object')'; myLVParam.Attributes = {'FontName'}; % name is default property mdladvObj.setListViewParameters({myLVParam});
An action provides a way for you to specify an action that the Model Advisor performs to fix a Model Advisor check. When you define an action, the Model Advisor window includes an Action box below the Analysis box.
You define actions using the ModelAdvisor.Action class inside a custom check function (see Defining Custom Checks). You must define:
One instance of this class for each action that you want to take.
One action callback function for each action (see Action Callback Function).
Note
|
The following is an example of defining actions within a custom check. You must include action definitions inside a check definition function (see Model Advisor Code Example: Check Definition Function).
The following code, when included in a check definition function, provides the information to populate the Action box in the Model Advisor.
rec = ModelAdvisor.Check('mathworks.example.optimizationSettings'); % Define an automatic fix action for this check modifyAction = ModelAdvisor.Action; modifyAction.setCallbackFcn(@modifyOptmizationSetting); modifyAction.Name = 'Modify Settings'; modifyAction.Description = ['Modify model configuration optimization' ... ' settings that can impact safety']; modifyAction.Enable = true; rec.setAction(modifyAction);
The Model Advisor, in the right pane, displays an Action box.

![]() | Registering Checks and Process Callbacks | Creating Callback Functions and Results | ![]() |

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 |