MATLAB Report Generator | ![]() ![]() |
Editing execute.m to Insert a Figure into the Report
Open the execute.m
file, which runs the component when the report is generated. Edit the file so that the component uses the new isVisibleAxes
and AxesColor
attributes that you just created. The new code will also insert a snapshot of the random plot figure into the report instead of returning the figure handle as text.
To complete this task, replace the old lines of code with the new lines of code shown below.
function out=execute(c) %EXECUTE returns a report element during generation %Create the figure. figHandle=figure('Name',c.att.Plot_Title); %Create the axes and make them a child of the figure axHandle=axes('Parent',figHandle); %Turn axes visibility on or off depending %on the value of the isVisibleAxes attribute if c.att.isVisibleAxes axis on; else axis off; end %This creates the data to be plotted %and displays it in the axes. The %number of lines to be plotted is %defined by the NumLines property. plotData=rand(10,floor(c.att.NumLines)); plot(plotData,'Parent',axHandle); %Set the axes "Color" property to be the value of %the AxesColor attribute. set(axHandle,'Color',c.att.AxesColor); %Now that we have created the figure, we want %to display it in the report. %Create a HG Figure Snapshot component snapComp=c.rptcomponent.comps.chgfigsnap; %Set the title of the resulting snapshot %to be the Plot_Title attribute. snapComp.att.ImageTitle=c.att.Plot_Title; %Since the random plot figure is the current %figure, it will be the one captured by the %snapshot component. This command runs the %snapshot component and returns the DocBook %<figure> tag. The second argument to %runcomponent shows the priority of the %"Running Component" message in the Generation %Status tab. out=runcomponent(snapComp,6); %Clean up by deleting the figure delete(figHandle)
Note the second argument to runcomponent
in the line
sets the message priority level to 6. If you set the Generation Status message priority level in the Setup File Editor to be less than 6, then no messages will be generated for this component as it is executing. See Setting the Generation Status Update Priority Level for a discussion on the message priority level.
![]() | Running the New Component | The Report Created by the Figure Random Plot Component | ![]() |