Skip to Main Content Skip to Search
Product Documentation

Registering Checks and Process Callbacks

Create sl_customization Function

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

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.

Registering Checks and Process Callbacks

To register custom checks and process callbacks, the customization manager includes the following methods:

Model Advisor Code Example: Registering Custom Checks and Process Callbacks

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);

Defining Startup and Post-Execution Actions Using Process Callback Functions

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:

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.

Process Callback Function Arguments

The process callback function takes the following arguments.

ArgumentI/O TypeData TypeDescription
stageInputEnumerationSpecifies 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.
systemInputPathModel or subsystem that the Model Advisor analyzes.
checkCellArrayInput/OutputCell arrayAs input, the array of checks constructed in the check definition function.

As output, the array of checks modified by actions in the configure stage.
taskCellArrayInput/OutputCell arrayAs input, the array of tasks constructed in the task definition function.

As output, the array of tasks modified by actions in the configure stage.

Model Advisor Code Example: Process Callback Function

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
  


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