getCheckResultData
Obtain Model Advisor check result data
Description
For a Model Advisor object, use the
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 results
= getCheckResultData(ma
,checkID
)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).
Examples
Get Model Advisor Check Result Data
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
.
openExample('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) addModelAdvisorCheckFcn(cm,@defineModelAdvisorCheck); end % ----------------------------- % define Model Advisor Check % ----------------------------- function defineModelAdvisorCheck mdladvRoot = ModelAdvisor.Root; % Definition for my custom check rec = ModelAdvisor.Check('myCustomCheckID'); rec.Title = 'My Custom Check Title'; rec.setCallbackFcn(@myCustomCheckCallbackFunc,'None','StyleThree'); % Specify a "Fix" action myAction = ModelAdvisor.Action; myAction.Name = 'My Custom Check Action'; myAction.setCallbackFcn(@myCustomCheckAction); rec.setAction(myAction); rec.ListViewVisible = true; mdladvRoot.publish(rec,'CUSTOM CHECK FOLDER'); end 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") setCheckResultStatus(mdladvObj,'fail'); setActionEnable(mdladvObj, 1); affectedBlockIDs = [affectedBlockIDs blockIDs(i)]; else setCheckResultStatus(mdladvObj, 'pass'); end end % Add the affected "Terminator" block IDs to the check result data setCheckResultData(mdladvObj, affectedBlockIDs); end 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) set_param(affectedBlocksIDs(i),'HideAutomaticName','off'); end % create the return text result = ModelAdvisor.Paragraph; addItem(result, 'Updated "Terminator" blocks to show the automatic name.'); % disable the action button setActionEnable(mdladvObj, false); end
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:
Advisor.Manager.refresh_customizations
Open Model Advisor on the model.
modeladvisor('sldemo_bounce')
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
ma
— Model Advisor object
Simulink.ModelAdvisor
object
Model Advisor object that you want to obtain check result data for, specified as a
Simulink.ModelAdvisor
object.
checkID
— Check IDs associated with Model Advisor checks
character vector | cell array of character vectors
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: 'mathworks.design.UnconnectedLinesPorts'
Output Arguments
results
— Check results
cell array
Check results, returned as a cell array. The data format depends on the checks that generate the data.
Version History
Introduced in R2006a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)