User`s guide

13 Create a Report Program
13-108
1
Create a message dispatcher.
dispatcher = MessageDispatcher.getTheDispatcher;
2
Add a listener using the MATLAB addlistener function.
l = addlistener(dispatcher,'Message', ...
@(src, evtdata) disp(evtdata.Message.formatAsText));
3
Dispatch the message, using the Message.dispatch method. Specify the dispatcher
object and the message to dispatch. Here the message is a debug message called
starting chapter, and the Document object d is the source of the message.
dispatch(dispatcher,ProgressMessage('starting chapter',d));
4
Include code to delete the listener, after the code that generates the report.
delete(l);
This report uses this progress message.
import mlreportgen.dom.*;
d = Document('test','html');
dispatcher = MessageDispatcher.getTheDispatcher;
l = addlistener(dispatcher,'Message', ...
@(src, evtdata) disp(evtdata.Message.formatAsText));
open(d);
dispatch(dispatcher,ProgressMessage('starting chapter',d));
p = Paragraph('Chapter ');
p.Tag = 'chapter title';
p.Style = { CounterInc('chapter'),...
CounterReset('table'),WhiteSpace('pre') };
append(p, AutoNumber('chapter'));
append(d,p);
close(d);
rptview('test','html');
delete(l);
The MATLAB Command Window displays progress messages, including the starting
chapter message, as well as the messages the DOM API dispatches by default.