This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Format Check Results

Format Results

You can make the analysis results of your custom checks appear similar to each other with minimal scripting using the ModelAdvisor.FormatTemplate class.

If this format template does not meet your needs, or if you want to format action results, use the Model Advisor Formatting API to produce formatted outputs in the Model Advisor. The following constructors of the ModelAdvisor class allow you to format the output.

ConstructorDescription
ModelAdvisor.Text

Create Model Advisor text output.

ModelAdvisor.List

Create list.

ModelAdvisor.Table

Create table.

ModelAdvisor.Paragraph

Create and format paragraph.

ModelAdvisor.LineBreak

Insert line break.

ModelAdvisor.Image

Include image in Model Advisor output.

Format Text

Text is the simplest form of output. You can format text in many different ways. The default text formatting is:

  • Empty

  • Default color (black)

  • Unformatted (not bold, italicized, underlined, linked, subscripted, or superscripted)

To change text formatting, use the ModelAdvisor.Text constructor. When you want one type of formatting for all text, use this syntax:

ModelAdvisor.Text(content, {attributes})
When you want multiple types of formatting, you must build the text.
t1 = ModelAdvisor.Text('It is ');
t2 = ModelAdvisor.Text('recommended', {'italic'});
t3 = ModelAdvisor.Text(' to use same font for ');
t4 = ModelAdvisor.Text('blocks', {'bold'});
t5 = ModelAdvisor.Text(' for a uniform appearance in the model.');

result = [t1, t2, t3, t4, t5];
Add ASCII and Extended ASCII characters using the MATLAB® char command. For more information, see the ModelAdvisor.Text class page.

Format Lists

You can create two types of lists: numbered and bulleted. The default list formatting is bulleted. Use the ModelAdvisor.List constructor to create and format lists. You can create lists with indented subsections, formatted as either numbered or bulleted.

subList = ModelAdvisor.List();
subList.setType('numbered')
subList.addItem(ModelAdvisor.Text('Sub entry 1', {'pass','bold'}));
subList.addItem(ModelAdvisor.Text('Sub entry 2', {'pass','bold'}));

topList = ModelAdvisor.List();
topList.addItem([ModelAdvisor.Text('Entry level 1',{'keyword','bold'}), subList]);
topList.addItem([ModelAdvisor.Text('Entry level 2',{'keyword','bold'}), subList]);

Format Tables

The default table formatting is:

  • Default color (black)

  • Left justified

  • Bold title, row, and column headings

Change table formatting using the ModelAdvisor.Table constructor.

This example creates a subtable within a table.

table1 = ModelAdvisor.Table(1,1);
table2 = ModelAdvisor.Table(2,3);
table2.setHeading('Table 2');
table2.setHeadingAlign('center');
table2.setColHeading(1, 'Header 1');
table2.setColHeading(2, 'Header 2');
table2.setColHeading(3, 'Header 3');
table1.setHeading('Table 1');
table1.setEntry(1,1,table2);

This example creates a table with five rows and five columns containing randomly generated numbers. Use the MATLAB code in a callback function to create the table. The Model Advisor displays table1 in the results.

% ModelAdvisor.Table example

matrixData = rand(5,5) * 10^5;

% initialize a table with 5 rows and 5 columns (heading rows not counting)
table1 = ModelAdvisor.Table(5,5);

% set column headings
for n=1:5
    table1.setColHeading(n, ['Column ', num2str(n)]);
end

% set alignment of second column heading
table1.setColHeadingAlign(2, 'center');

% set column width of second column
table1.setColWidth(2, 3);

% set row headings
for n=1:5
    table1.setRowHeading(n, ['Row ', num2str(n)]);
end

% set Table content
for rowIndex=1:5
    for colIndex=1:5
        table1.setEntry(rowIndex, colIndex, ...
            num2str(matrixData(rowIndex, colIndex)));

        % set alignment of entries in second row
        if colIndex == 2
            table1.setEntryAlign(rowIndex, colIndex, 'center');
        end
    end
end

% overwrite content of cell 3,3 with a ModelAdvisor.Text
text = ModelAdvisor.Text('Example Text');
table1.setEntry(3,3, text)

Format Paragraphs

You must handle paragraphs explicitly because most markup languages do not support line breaks. The default paragraph formatting is:

  • Empty

  • Default color (black)

  • Unformatted, (not bold, italicized, underlined, linked, subscripted, or superscripted)

  • Aligned left

If you want to change paragraph formatting, use the ModelAdvisor.Paragraph class.

Formatted Output

The following is the example from Simple Check Callback Function, reformatted using the Model Advisor Formatting API.

function result = SampleStyleOneCallback(system)
mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system);
if strcmp(get_param(bdroot(system), 'ScreenColor'),'white')
    result = ModelAdvisor.Text('Passed',{'pass'});
    mdladvObj.setCheckResultStatus(true);
else
    msg1 = ModelAdvisor.Text(...
        ['It is recommended to select a Simulink window screen color'...
        ' of white to ensure a readable and printable model. Click ']);
    msg2 = ModelAdvisor.Text('here');
    msg2.setHyperlink('matlab: set_param(bdroot,''ScreenColor'',''white'')');
    msg3 = ModelAdvisor.Text(' to change screen color to white.');
    result = [msg1, msg2, msg3];
    mdladvObj.setCheckResultStatus(false);
end

Format Linebreaks

You can add a line break between two lines of text with the ModelAdvisor.LineBreak constructor.

result = ModelAdvisor.Paragraph;
addItem(result, [resultText1 ModelAdvisor.LineBreak resultText2]);

Format Images

To include an image in Model Advisor output, use the ModelAdvisor.Image constructor. To create an Image object, use this syntax.

image_obj = ModelAdvisor.Image;

See Also

| |

Related Examples

More About