Report Generator figures: List of figures not working
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm trying to generate automatically a figure report from currently open figures list. I'm using code reported below. My issue is, I'm not able to create a coherent list of figures and a summary of illlustrations to link to single images. It looks my code is not too different from examples, so I don't find reasons for not working... Please help! (Sorry for dirty coding but is a WIP):
function ReportFigures(ReportName,fileType)
if nargin<2
fileType='pdf';
end
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report(ReportName,fileType);
open(rpt);
toc = TableOfContents();
append(rpt,toc);
lof = ListOfFigures();
lof.Title = "List of Figures";
append(rpt,lof);
ch = Chapter("Images");
p = Paragraph('Pictures from script');
p.Style = {Color('red'),FontFamily('Arial'),FontSize('18pt')};
p.Style = {OuterMargin('0.5in','0in','0in','12pt')};
p.HAlign = 'center';
% ch.Style = {Color('red'),FontFamily('Arial'),FontSize('18pt')};
append(ch,p);
h= findall(groot,'Type','figure')
for k=1:length(h)
fileImageName=['Tmp' num2str(k) '.png'];
saveas(h(k),fileImageName);
%image1 = FormalImage(which(get(h(k),'Name')))
image1(k)=Image(fileImageName);
%image1=Image(getSnapshotImage(h(k),rpt));
%image1.ScaleToFit = true;
%image1(k).Caption = get(h(k),'Name');
% image1
image1(k).Height = "3in";
image1(k).Width = "5in";
% image1.Title=get(h(k),'Name');
append(p,image1(k));
% surf(peaks);
% fig = Figure();
% fig.Snapshot.Caption = '3-D shaded surface plot';
% fig.Snapshot.Height = '5in';
% fig=h(k);
% fig.Snapshot.Caption = get(h(k),'Name');
% fig.Snapshot.Height = "5in";
% append(ch,fig);
end
append(rpt,ch);
%delete(gcf);
close(rpt);
rptview(rpt);
end
채택된 답변
Madheswaran
2024년 9월 4일
Hello,
It seems you are trying to use the 'Caption' property with the ‘mlreportgen.dom.Image’ class, which doesn't support this property. To generate a list of figures, I recommend using the ‘mlreportgen.report.FormalImage’ class which allows you to add captions. Additionally, append the images directly to the 'Chapter' rather than to a 'Paragraph'.
Here's the revised code that should meet your requirements:
% ... existing code
h = findall(groot, 'Type', 'figure');
for k = 1:length(h)
fileImageName = ['Tmp' num2str(k) '.png'];
saveas(h(k), fileImageName);
% Create a formal image
img = FormalImage(fileImageName);
img.Caption = get(h(k), 'Name');
img.Height = '3in';
img.Width = '5in';
% Append the image directly to the chapter
append(ch, img);
end
append(rpt, ch);
% ... existing code
The modified code will help you to add the list of figures section as shown in the below image:

For further details, please refer to the following MATLAB documentations:
- FormalImage - https://mathworks.com/help/rptgen/ug/mlreportgen.report.formalimage-class.html
- List of Figures - https://mathworks.com/help/rptgen/ug/mlreportgen.report.listoffigures-class.html
Hope this helps!
댓글 수: 0
추가 답변 (1개)
ENRICO
2024년 9월 6일
댓글 수: 1
Madheswaran
2024년 9월 9일
Glad my answer helped you. To answer your doubt, to generate the list of figures, you should insert the image using mlreportgen.report.FormalImage or mlreportgen.report.Figure objects with captions as mentioned in the documentation: https://mathworks.com/help/rptgen/ug/mlreportgen.report.listoffigures-class.html
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Report Generator Task Examples에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!