Main Content


Set result data for currently running check



Use the success = setCheckResultData(ma,data) function to set the check result data for the currently running check. Only the callback function of a check can invoke this function. You can get the check result data by using the function getCheckResultData.

This function enables you to set result data for custom checks that you create with the Model Advisor customization API, an optional feature that is available with Simulink® Check™ software. For more information, see Define Custom Model Advisor Checks (Simulink Check).


collapse all

Define a custom Model Advisor check and use the setCheckResultData 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 setCheckResultData in the check callback function to save the IDs of the blocks that failed the check. The action callback function uses the function getCheckResultData to access that data. 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

Simulink.ModelAdvisor object for which you want to set result data for the currently running check.

Result data that you specify for a custom check.

Output Arguments

collapse all

Boolean value that indicates whether the Model Advisor successfully set result data for the currently running check. A value of 1 indicates that the Model Advisor successfully set the data. A value of 0 indicates that the Model Advisor did not set the data.

Version History

Introduced in R2006a