Error occurred when I tried to copy tiledlayout object to mlreportge​n.report.F​igure and append it to mlreportge​n.report.R​eport in App Designer

3 Ansichten (letzte 30 Tage)
Hello team and community,
I am working on an app in MATLAB App Designer.
Here I tried to generate a report from mlreportgen.report and mlreportgen.dom.
I initially plotted my reults in an TabGroup with tiledlayout as the attachment image.
And I would like to copy this plot into a figure and create it in a mlreportgen.report.Figure with following code.
% The part of the code that went wrong
% Figure results
sec2_2 = Section;
sec2_2.Title = 'Results plot';
for i = 3:numel(app.TabGroup2.Children)
t = app.TabGroup2.Children(i);
pos = get(t,'Position');
f1 = figure('Visible','off');
set(f1,'Position',pos)
s = copyobj(t.Children,f1);
fig4 = Figure(s);
append(sec2_2,fig4);
close(f1);
end
append(ch2,sec2_2);
append(rpt,ch2); % error occured here
However, I received the following error and I have hard time to understand want could be wrong for debugging.
Interestingly, when I used pause for degugging and I excuted the above code in another script, I was able to excute without error.
Could anyone explaine why this error occured?
Error using matlab.graphics.chart.decoration.ConstantLine/setParentImpl
Parent must be a Cartesian axes.
Error in matlab.graphics.internal.figfile.FigFile/read (line 31)
hgDataVars = load(filename, '-mat', '-regexp', '^hg[M]');
Error in matlab.graphics.internal.figfile.FigFile
Error in loadFigure (line 31)
FF = matlab.graphics.internal.figfile.FigFile(fullpath);
Error in openfig>localOpenFigure (line 75)
h = loadFigure(filename, visibleAction);
Error in openfig (line 40)
figOut = localOpenFigure(filename, reuse, visibleAction);
Error in mlreportgen.report.MATLABGraphicsContainer/getSnapshotImageImpl
Error in mlreportgen.report.MATLABGraphicsContainer/getContent
Error in mlreportgen.report.ReportForm/fillHole
Error in mlreportgen.report.ReporterBase/processHole
Error in mlreportgen.report.ReportForm/fillForm
Error in mlreportgen.report.ReporterBase/getDocumentPart
Error in mlreportgen.report.ReporterBase/getImpl
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.ReportForm/fillHole
Error in mlreportgen.report.Section/processHole
Error in mlreportgen.report.ReportForm/fillForm
Error in mlreportgen.report.ReporterBase/getDocumentPart
Error in mlreportgen.report.ReporterBase/getImpl
Error in mlreportgen.report.Section/getImpl
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.ReportForm/fillHole
Error in mlreportgen.report.Section/processHole
Error in mlreportgen.report.Chapter/processHole
Error in mlreportgen.report.ReportForm/fillForm
Error in mlreportgen.report.ReporterBase/getDocumentPart
Error in mlreportgen.report.ReporterBase/getImpl
Error in mlreportgen.report.Section/getImpl
Error in mlreportgen.report.internal.LockedForm.add
Error in mlreportgen.report.ReportBase/append
Error in redesign/ExportButtonPushed (line 4976)
append(rpt,ch2);
Thank you very much.
Best,
Jesse

Antworten (1)

Divyanshu
Divyanshu am 24 Aug. 2023
Hi Jesse,
Here is sample code for copying or exporting a figure from tab-group into a report using mlreportgenfunction:
methods (Access = private)
% Code that executes after component creation
function demoFunction(app)
m = 2;
n = 1;
x = 1:10;
y = 2*x+1;
app.tiledlayout = tiledlayout(app.Panel,m,n);
ax1 = nexttile(app.tiledlayout,1);
plot(ax1,x,y);
ax2 = nexttile(app.tiledlayout,2);
plot(ax2,x,2*y);
end
% Button pushed function: CopyPlotButton
function copyFigure(app, event)
import mlreportgen.report.*
appPanel = app.TabGroup.Children(1).Children(2);
app.tiledlayout = appPanel.Children(1);
t = app.tiledlayout.Children;
fig = figure('Visible','off');
copyobj(t,fig);
pos = fig.Position;
rpt = Report('example','pdf');
add(rpt, "Sample Figure");
figReporter0 = Figure(fig);
add(rpt,figReporter0);
rptview(rpt)
end
end
In the above code, demoFunction is a startup function for the app which creates tiled layout and adds sample plots to the two tiles under the first tab in the tab-group.
Moreover, ‘copyFigure’ is a callback function which is called when the copyFigure button is clicked on the App. This function exports the entire tiled layout with sample plots into the report created using the ‘mlreportgen function of MATLAB.
Refer the following documentation for better understanding:

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by