|
|
|
| R2011b Documentation → Simulink Verification and Validation | |
Learn more about Simulink Verification and Validation |
|
| Contents | Index |
| On this page… |
|---|
Create sl_customization Function Registering Checks and Process Callbacks Defining Startup and Post-Execution Actions Using Process Callback Functions |
To add checks to the Model Advisor, on your MATLAB path, in the sl_customization.m file, create the sl_customization() function.
Tip
|
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 and process callbacks. Use these methods to register customizations specific to your application, as described in the following sections.
To register custom checks and process callbacks, the customization manager includes the following methods:
addModelAdvisorCheckFcn (@checkDefinitionFcn)
Registers the checks that you define in checkDefinitionFcn to the By Product folder of the Model Advisor.
The checkDefinitionFcn argument is a handle to the function that defines all custom checks that you want to add to the Model Advisor as instances of the ModelAdvisor.Check class (see Defining Custom Checks).
addModelAdvisorProcessFcn (@modelAdvisorProcessFcn)
Registers the process callback function for the Model Advisor checks (see Defining Startup and Post-Execution Actions Using Process Callback Functions).
Note The @ sign defines a function handle that MATLAB calls. For more information, see At — @ in the MATLAB documentation. |
The following code example registers custom checks and a process callback function:
function sl_customization(cm) % register custom checks cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks); % register custom process callback cm.addModelAdvisorProcessFcn(@ModelAdvisorProcessFunction);
Note If you add custom tasks and folders within the sl_customization.m file, include methods for registering the tasks and folders in the sl_customization function. For more information, see Registering Tasks and Folders. |
The process callback function is an optional function that you use to configure the Model Advisor and process check results at run time. The process callback function specifies actions that the software performs at different stages of Model Advisor execution:
configure stage: The Model Advisor executes configure actions at startup, after all checks and tasks have been initialized. At this stage, you can customize how the Model Advisor constructs lists of checks and tasks by modifying Visible, Enable, and Value properties. For example, you can remove, rename, and selectively display checks and tasks.
process_results stage: The Model Advisor executes process_results actions after checks complete execution. You can specify actions to examine and report on the results returned by check callback functions.
If you create a process callback function, you must register it, as described in Registering Checks and Process Callbacks. The following sections provide mode information about defining your own process callback functions.
The process callback function takes the following arguments.
| Argument | I/O Type | Data Type | Description |
|---|---|---|---|
| stage | Input | Enumeration | Specifies the stages at which process callback actions are executed. Use this argument in a switch statement to specify actions for the stages configure and process_results. |
| system | Input | Path | Model or subsystem that the Model Advisor analyzes. |
| checkCellArray | Input/Output | Cell array | As input, the array of checks constructed in the check definition function. As output, the array of checks modified by actions in the configure stage. |
| taskCellArray | Input/Output | Cell array | As input, the array of tasks constructed in the task definition function. As output, the array of tasks modified by actions in the configure stage. |
The following code is an example of a process callback function that specifies actions in the configure stage, to make only custom checks visible. In the process_results stage, this function displays information at the MATLAB command line for checks that do not pass.
% Process Callback Function % Defines actions to execute at startup and post-execution function [checkCellArray taskCellArray] = ... ModelAdvisorProcessFunction(stage, system, checkCellArray, taskCellArray) switch stage % Specify the appearance of the Model Advisor window at startup case 'configure' for i=1:length(checkCellArray) % Hide all checks that do not belong to custom folder if isempty(strfind(checkCellArray{i}.ID, 'mathworks.example')) checkCellArray{i}.Visible = false; checkCellArray{i}.Value = false; end end % Specify actions to perform after the Model Advisor completes execution case 'process_results' for i=1:length(checkCellArray) % Print message if check does not pass if checkCellArray{i}.Selected && (strcmp(checkCellArray{i}.Title, ... 'Check Simulink window screen color')) mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system); % Verify whether the check was run and if it failed if mdladvObj.verifyCheckRan(checkCellArray{i}.ID) if ~mdladvObj.getCheckResultStatus(checkCellArray{i}.ID) % Display text in MATLAB Command Window disp(['Example message from Model Advisor Process'... ' callback.']); end end end end end
![]() | Quick Start Examples | Defining Custom Checks | ![]() |

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 |