Contenuto principale

ModelAdvisor.Text

Create Model Advisor text output

Description

Use ModelAdvisor.Text objects to create formatted text for display in the Model Advisor output.

Creation

Description

textObj = ModelAdvisor.Text creates a default text object for display in the Model Advisor output. The default text object contains no text, but you can set properties of the object to customize the text for display.

example

textObj = ModelAdvisor.Text(attribute) creates a text object for display in the Model Advisor output.

example

textObj = ModelAdvisor.Text(content,attribute) creates a text object that displays the text in content with the text styles in attribute.

example

Input Arguments

expand all

Text to display, specified as a string scalar or character vector. By default, content is empty, and the text object does not display any text in the Model Advisor output.

Add ASCII and Extended ASCII characters using the MATLAB® char command.

Example: "Check passed"

Example: "bold"

Text formatting, specified as a cell array of character vectors that contain the text formatting options for the text content. By default, attribute is {"normal"}, and the object displays unformatted black text in the Model Advisor output. Possible formatting options include:

  • "normal" (default) — Text is black and unformatted.

  • "bold" — Text is bold.

  • "italic" — Text is italicized.

  • "underline" — Text is underlined.

  • "pass" — Text is green.

  • "warn" — Text is yellow.

  • "fail" — Text is red.

  • "keyword" — Text is blue.

  • "subscript" — Text is subscripted.

  • "superscript" — Text is superscripted.

Output Arguments

expand all

Text for the Model Advisor output, returned as a ModelAdvisor.Text object.

Object Functions

setBoldSet text as bold in Model Advisor analysis results
setColorSet text color in Model Advisor analysis results
setHyperlinkSet text as hyperlink in Model Advisor analysis results
setItalicSet text as italicized style in Model Advisor analysis results
setRetainSpaceReturnPreserve spaces and line breaks in Model Advisor analysis results
setSubscriptSet text as subscript in Model Advisor analysis results
setSuperscriptSet text as superscript in Model Advisor analysis results
setUnderlinedSet text as underlined in Model Advisor analysis results

Examples

collapse all

In this example, you create and combine text objects to customize the text output for the Model Advisor.

Text is the simplest form of output in the Model Advisor. You can specify and format this output text to highlight important information or improve readability.

Specify Formatted Text

Create a text object that applies italic.

textObj = ModelAdvisor.Text("MySampleText",{"italic"})
textObj = 
  Text with properties:

              Hyperlink: ''
                 IsBold: 0
               IsItalic: 1
           IsUnderlined: 0
          IsSuperscript: 0
            IsSubscript: 0
           RetainReturn: 0
      RetainSpaceReturn: 0
    ContentsContainHTML: 1
                  Color: 'Normal'
              SpanClass: ''
                  title: ''
                Content: 'MySampleText'
                    Tag: ''
         IsSingletonTag: 0
          TagAttributes: {0×2 cell}
        CollapsibleMode: 'none'
          HiddenContent: []

Combine Multiple Formatting Options

To apply different types of formatting within a single message, create several text objects and combine them.

t1 = ModelAdvisor.Text("It is");
t2 = ModelAdvisor.Text("recommended",{"italic"});
t3 = ModelAdvisor.Text("to use same the font for");
t4 = ModelAdvisor.Text("blocks",{"bold"});
t5 = ModelAdvisor.Text("for a uniform appearance in the model.");
result = [t1,t2,t3,t4,t5];

Specify Conditional Text in Check Callback Function

To apply different types of formatting for simple check callback function.

function result = SampleStyleOneCallback(system)
% Get Model Advisor object for the current system
mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system);

% Check if the screen color of the Simulink model is white
if strcmp(get_param(bdroot(system),"ScreenColor"),"white")
    % If white, display a "Passed" message with pass formatting
    result = ModelAdvisor.Text("Passed",{"pass"});
    mdladvObj.setCheckResultStatus(true);
else
    % If not white, provide a recommendation and a clickable link
    msg1 = ModelAdvisor.Text("It is recommended that you select a Simulink window screen color of white for a readable and printable model. Click");
    msg2 = ModelAdvisor.Text("here");
    msg2.setHyperlink("matlab: set_param(bdroot,''ScreenColor'',''white'')");
    msg3 = ModelAdvisor.Text("to change the screen color to white.");
    result = [msg1,msg2,msg3];
    mdladvObj.setCheckResultStatus(false);
end
end

Version History

Introduced in R2006b