setCheckResultData
Set result data for currently running check
Description
Use the
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 success
= setCheckResultData(ma
,data
)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).
Examples
Set Model Advisor Check Result Data
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
.
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 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:
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
Simulink.ModelAdvisor
object for which you want to set result
data for the currently running check.
data
— Result data
cell array of character vectors
Result data that you specify for a custom check.
Output Arguments
success
— Boolean
value indicating whether result data is set
Boolean
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
See Also
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)