Report Generator figures: List of figures not working
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ENRICO
el 29 de Ag. de 2024
Comentada: Madheswaran
el 9 de Sept. de 2024
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
Respuesta aceptada
Madheswaran
el 4 de Sept. de 2024
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 comentarios
Más respuestas (1)
ENRICO
el 6 de Sept. de 2024
1 comentario
Madheswaran
el 9 de Sept. de 2024
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
Ver también
Categorías
Más información sobre Title Pages, Tables of Contents, Lists of Figures, Tables, and Captions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!