Main Content


Obtain Model Advisor check result data



For a Model Advisor object, use the results = getCheckResultData(ma,checkID) function to get the check result data for a specified set of checks. You set the check result data for a check by using the setCheckResultData function in the check callback function.

This function enables you to access results generated by custom checks that you create using the Model Advisor customization API, an optional feature available with Simulink® Check™. For more information, see Define Custom Model Advisor Checks (Simulink Check).


collapse all

Define a custom Model Advisor check and use the getCheckResultData function to pass data from the check callback function to the check action callback function.

This example uses Simulink Check.

Open the example model sldemo_bounce.


Create an sl_customization.m file in the current working folder. In MATLAB®, in the Home tab, click New Script. Copy and paste this code and save the file as sl_customization.m.

function sl_customization(cm)
    % register custom check with the customization manager object (cm)

% -----------------------------
% define Model Advisor Check
% -----------------------------
function defineModelAdvisorCheck
    mdladvRoot = ModelAdvisor.Root;
    % Definition for my custom check
    rec = ModelAdvisor.Check('myCustomCheckID');
    rec.Title = 'My Custom Check Title';
    % Specify a "Fix" action
    myAction = ModelAdvisor.Action;
    myAction.Name = 'My Custom Check Action';
    rec.ListViewVisible = true;
    mdladvRoot.publish(rec,'CUSTOM CHECK FOLDER');

function [ResultDescription, ResultDetails] = myCustomCheckCallbackFunc(system)
    % Initialize empty arrays
    ResultDescription = {};
    ResultDetails     = {};
    affectedBlockIDs = [];

    % Get the Model Advisor handle for the current model or subsystem
    mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system);

    % Find the "Terminator" blocks
    blockIDs = Simulink.findBlocksOfType(system,'Terminator');

    % Check if the "Terminator" block hides the automatic block name
    % If the name is hidden, fail the check and enable the Action
    for i = 1:numel(blockIDs)
        if (get_param(blockIDs(i),'HideAutomaticName') == "on")
            setActionEnable(mdladvObj, 1);
            affectedBlockIDs = [affectedBlockIDs blockIDs(i)];
            setCheckResultStatus(mdladvObj, 'pass');

    % Add the affected "Terminator" block IDs to the check result data
    setCheckResultData(mdladvObj, affectedBlockIDs);

function result = myCustomCheckAction(taskobj)
    mdladvObj = taskobj.MAObj;
    % Get the affected "Terminator" block IDs from the check results
    affectedBlocksIDs = getCheckResultData(mdladvObj, 'myCustomCheckID');
    % Make the automatic name visible for the "Terminator" blocks
    for i=1:length(affectedBlocksIDs)
    % create the return text
    result = ModelAdvisor.Paragraph;
    addItem(result, 'Updated "Terminator" blocks to show the automatic name.');                
    % disable the action button
    setActionEnable(mdladvObj, false);


This code defines a custom check that finds the Terminator blocks in a model and checks if those blocks hide the automatic block name. If the automatic block name is hidden, the check fails and enables an action that can update the Terminator blocks in the model to show the automatic block name. The code uses the function getCheckResultData in the action callback function to get the IDs of the blocks that failed the check. For more information on custom check callback functions and action callback functions, see Define Custom Model Advisor Checks (Simulink Check).

Update the environment to include the custom Model Advisor check defined in the sl_customization.m file. In the MATLAB Command Window, enter:


Open Model Advisor on the model.


Select and run the custom Model Advisor check. In the left pane, select By Product > CUSTOM CHECK FOLDER > My Custom Check Title and click Run Checks.

The check fails because the Terminator blocks in the sldemo_bounce model hide the automatic block name.

Right-click the check and click Fix This Check.

The check runs the action callback to update the Terminator blocks to show the automatic block name. If you re-run the check, the check now passes.

Input Arguments

collapse all

Model Advisor object that you want to obtain check result data for, specified as a Simulink.ModelAdvisor object.

Check IDs associated with Model Advisor checks that you want to obtain results from, specified as a character vector or cell array of character vectors.

Example: ''

Output Arguments

collapse all

Check results, returned as a cell array. The data format depends on the checks that generate the data.

Version History

Introduced in R2006a