Formatting Model Advisor Outputs

What Is the Model Advisor Formatting API?

You can use the Model Advisor Formatting API to produce formatted outputs in Model Advisor. The following constructors of the ModelAdvisor class provide the ability to format the output. For more information on each constructor and associated methods, click the link in the Constructor column.

ConstructorDescription
ModelAdvisor.TextFormats element text.
ModelAdvisor.ParagraphCombines elements into paragraph format.
ModelAdvisor.ListCreates a list of elements.
ModelAdvisor.LineBreakAdds a line break between elements.
ModelAdvisor.TableCreates a table.
ModelAdvisor.ImageAdds an image to the output.

Formatting Text

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

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

ModelAdvisor.Text(content, {attributes})

When you want multiple types of formatting, you must build the text, as shown in the next example:

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(' to ensure uniform appearance of model.');

result = [t1, t2, t3, t4, t5];

You can add ASCII and Extended ASCII characters using the MATLAB® char command. See the ModelAdvisor.Text constructor reference for more information.

Formatting 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 (see ModelAdvisor.List). You can create lists with indented subsections, formatted as either numbered or bulleted, as shown in the next example:

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]);

Formatting Tables

The default table formatting is:

You can change table formatting using the ModelAdvisor.Table constructor (see ModelAdvisor.Table). The following example code creates a subtable within a table, as shown in the figure:

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);

Formatting Paragraphs

Paragraphs need to be handled explicitly because most markup languages do not support line breaks. The default paragraph formatting is:

If you want to change paragraph formatting, use the ModelAdvisor.Paragraph constructor (see ModelAdvisor.Paragraph).

Code Example: Model Advisor 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
  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS