Main Content

setData

Class: ModelAdvisor.ResultDetail
Package: ModelAdvisor

Associate Simulink Identifier with ModelAdvisor.ResultDetail object

Syntax

setData(ElementResults,violationBlks)

Description

For a custom Model Advisor check, the setData(ElementResults,violationBlks) method associates the Simulink Identifier (SID) of a block that violates a check with a ModelAdvisor.ResultDetail object.

As part of the check callback function, you create ModelAdvisor.ResultDetail objects for each block that the find_system() API returns as violating the check.

Use the setResultDetails method to associate the results with the ModelAdvisor.Check object. The ModelAdvisor.ResultDetail objects are saved as part of the ResultDetails property of the ModelAdvisor.Check class.

Input Arguments

expand all

ModelAdvisor.ResultDetail objects corresponding to each block that violates a custom Model Advisor check

Array of handles to blocks that violate a check

Examples

This example shows result details that correspond to the execution of check Check whether block names appear below blocks in the AdvisorCustomizationExample model. To view the files in this example, see Create and Deploy a Model Advisor Custom Configuration.

Define a Collection of Result Detail Objects

The defineDetailStyleCheck check definition function contains the DetailStyleCallback check callback function. To return model elements in the system that meet a specified criteria, the DetailStyleCallback function uses the find_system API. In this example, the find_system() API returns blocks whose name does not appear below the block (violationBlks).

% find all blocks whose name does not appear below blocks
violationBlks = find_system('System','Type','block','NamePlacement','alternate','ShowName', 'on');

ModelAdvisor.ResultDetail creates ResultDetailObjs for each model element returned by the find_system API. When violationBlks is empty, the ElementResults collection consists of a single object. The Name,Value pairs define the collection for a nonviolated check. For this type of collection, the Simulink.ModelAdvisor.setCheckResultStatus(true) method specifies that the check is not violated and displays Passed on the Model Advisor.

In this code sample, the find_system API does not identify blocks whose name appears below the block, therefore ElementResults provides information content only.

if isempty(violationBlks)
    ElementResults = ModelAdvisor.ResultDetail;
    ElementResults.IsInformer = true;
    ElementResults.Description = 'Identify blocks where the name is not displayed below the block.';
    ElementResults.Status = 'All blocks have names displayed below the block.';       
    mdladvObj.setCheckResultStatus(true);                

When the find_system API returns a list of model elements that meet specified criteria, the ModelAdvisor.ResultDetail class creates a ResultDetailObjs object for each element in violationBlks. The Name,Value pairs define ElementResults as a collection of objects that violate the check. For this collection, the Simulink.ModelAdvisor.setCheckResultStatus(false) method specifies that the check is violated and displays Warning or Failed on the Model Advisor. The Simulink.ModelAdvisor.setActionEnable(true) method enables the ability to fix the check violation issue from the Model Advisor.

In this code sample, the find_system API returns a list of blocks whose name appears below the block. ElementResults includes each ResultDetailObjs object that violates the check and provides a recommended action message for fixing the check violation.

else
    for i=1:numel(violationBlks)
	 ElementResults(1,i) = ModelAdvisor.ResultDetail;
    end
    for i=1:numel(ElementResults)
        ModelAdvisor.ResultDetail.setData(ElementResults(i), 'SID',violationBlks{i});  
        ElementResults.Description = 'Identify blocks where the name is not displayed below the block.';  
        ElementResults.Status = 'The following blocks have names that do not display below the blocks:';   
        ElementResults.RecAction = 'Change the location such that the block name is below the block.'; 
    end                
    mdladvObj.setCheckResultStatus(false);  
    mdladvObj.setActionEnable(true);          
 

The ModelAdvisor.Check.setResultDetails method associates the results with the check (CheckObj).

CheckObj.setResultDetails(ElementResults);   
 

After executing the check, you can view the results in the Model Advisor as a collection, such as by recommended action, block, or subsystem. To define this report style, specify 'DetailStyle' as the callback style in the ModelAdvisor.Check.setCallbackFcn method.

% Create ModelAdvisor.Check object and set properties.
rec = ModelAdvisor.Check('com.mathworks.sample.detailStyle');
rec.Title = 'Check whether block names appear below blocks';  
rec.TitleTips = 'Check position of block names';
rec.setCallbackFcn(@DetailStyleCallback,'None','DetailStyle');
    

Introduced in R2018b