Generate an Embedded Web View Report

To generate an embedded Web View report, create an instance of the class that defines the report generator (see Create an Embedded Web View Report Generator). Then, use the fill and close report generator methods.

For example, suppose that you want to create a report using the SimulinkDesignVariables class example (see Class Definition File for an Embedded Web View). These commands generate and display an instance of that report:

model = 'f14';
rptName = sprintf('%sVariables', model);
load_system(model);
rpt = SystemDesignVariables(rptName, model);
fill(rpt);
close(rpt);
close_system(model);
rptview(rptName);

The fill(rpt) command uses the fill method, which the report generator inherits from its base class. This method embeds a Web View of the f14 model in the report. It also calls the fillContent method of the report generator, which fills the report document pane with a report on the variables used by the f14 model.

The resulting Embedded Web View report is shown.

For information on navigating to different parts of the report, see Navigating an Embedded Web View Report.

Class Definition File for an Embedded Web View

This class generates a report on the workspace and data dictionary variables used by a specified Simulink® model. This example class includes the values of scalar numeric variables only.

classdef SystemDesignVariables < slreportgen.webview.EmbeddedWebViewDocument
    %SystemDesignVariables Report on variables used by a Simulink model
    %   Defines a class of report generators to produce HTML reports on
    %   the workspace and data dictionary variables used by a Simulink
    %   model. The generated report includes this information for
    %   each variable:
    %   
    %   Value (if the value is a scalar, numeric value)
    %   Data Type
    %   Source (e.g, path of dictionary containing the variable)
    %   Source Type (e.g., data dictionary or base workspace)
    %   Users (path of blocks that use the variable)
    %
    %   The report includes a Web View of the model with two-way
    %   links between design variable user paths and blocks in the Web
    %   View that use the design variables.
    %
        
    methods
        
        function rpt = SystemDesignVariables(reportPath, modelName)
            
            % Invoke the EmbeddedWebViewDocument constructor, which
            % saves the report path and model name for use by the
            % report's fill methods.
            rpt@slreportgen.webview.EmbeddedWebViewDocument(reportPath,...
                modelName);
            
            % Turn off duplicate link warnings to avoid warnings for
            % blocks that use multiple design variables.
            rpt.ValidateLinksAndAnchors = false;
            
            rpt.ExportOptions.IncludeMaskedSubsystems = true;
            rpt.ExportOptions.IncludeSimulinkLibraryLinks = true;
            rpt.ExportOptions.IncludeReferencedModels = true;
        end
        
        function fillContent(rpt)
            % Fill the Content hole in the report template with design
            % variable information. The rpt variable is a subclass of the 
            % DOM Document class, so you can use DOM methods to create, 
            % format, and append content to this report.
            
            %% Set up report
            % Allow use of unqualified names for DOM objects, 
            % such as Paragraph instead of mlreportgen.dom.Paragraph.
            import mlreportgen.dom.*
            
            % Obtain model name, which was saved by the report
            % constructor. getExportedModels returns model names as a
            % cell array, in case a report uses multiple models.
            model = getExportModels(rpt);
            
            % Extract the model from the cell array. (This report uses 
            % only one model.)
            model= model{1};
            
            %% Create report title
            title = Paragraph(sprintf('%s Design Variables',model));
            title.Style = {Bold,Color('white'),BackgroundColor('gray'), ...
                FontFamily('Helvetica'),FontSize('18pt')};
            append(rpt,title);
            
            %% Find all variables used by this model.
            vars = Simulink.findVars(model,'ReturnResolvedVar',true);
            
            %% Loop through the variable information returned by 
            % Simulink.findVars, converting the info to formatted document 
            % objects and appending the formatted info to the report.
            nVars = numel(vars);
            for i = 1:nVars
                
                % var is a Simulink.VariableUsage object
                var = vars(i);
                
                %% Create variable section heading
                varHeading = Heading1(var.Name);
                varHeading.Style = {FontFamily('Helvetica'),...
                    FontSize('16pt'),OuterMargin('0pt','0pt','12pt','0pt')};
                append(rpt,varHeading);
                rule = HorizontalRule;
                rule.Style = {Color('LightGray'), ...
                    OuterMargin('0pt','0pt','0pt','0pt')};
                append(rpt, rule);
                
                %% Format variable info
                
                % Convert the variable information into a cell array
                % by using the DOM Table class.
                info = cell(5,1);
                info{1,1} = 'Value:';
                value = var.Value;
                type = class(value);
                if isa(value,'Simulink.Parameter')
                    value = value.Value;
                end
                if isnumeric(value) && isscalar(value)
                    info{1,2} = num2str(value);
                else
                    % Insert logic here to handle non-scalar values.
                    info{1,2} = 'n/a';
                end
                info{2,1} = 'Type:';
                info{2,2} = type;
                info{3,1} = 'Source:';
                info{3,2} = var.Source;
                info{4,1} = 'Source Type:';
                info{4,2} = var.SourceType;
                info{5,1} = 'Users:';
                
                % var.Users contains a cell array of the paths to the model
                % blocks that use this variable. Create two-way hyperlinks
                % between the paths and the corresponding elements in the
                % Web View of the model embedded in this report by this 
                % report's superclass, EmbeddedWebViewDocument. Note that
                % this fails when the Web View element already contains
                % a link, e.g., when the element uses more that one 
                % variable. In this case, the element links only to the
                % first variable that it uses.
                nUsers = numel(var.Users);
                users = Table(cell(nUsers,1));
                for u = 1:nUsers
                    userPath = var.Users{u};
                    userLink = createElementTwoWayLink(rpt,...
                                userPath,...
                                mlreportgen.dom.Paragraph(userPath));
                    userLink.Style = {OuterMargin('0pt', '0pt','0pt','0pt')};
                    append(users.entry(u,1),userLink);
                end               
                info{5, 2} = users;
                 
                %% Convert the usage info to a table, format the table,
                % and append the table to the rport.
                infoTable = Table(info);
                grp = TableColSpecGroup;
                grp.Style = {OuterMargin('0pt','0pt','0pt','0pt')};
                specs(1) = TableColSpec;
                specs(1).Style = {Bold};
                specs(2) = TableColSpec;
                grp.ColSpecs = specs;
                infoTable.ColSpecGroups = grp;
                
                append(rpt, infoTable);
                
            end
        end
    end
end