Report Generator figures: List of figures not working
6 次查看(过去 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 中查找有关 Title Pages, Tables of Contents, Lists of Figures, Tables, and Captions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!