Programmatically generating Report Generator

6 visualizaciones (últimos 30 días)
idriss Moffo
idriss Moffo el 1 de Mzo. de 2018
Comentada: Rahul Singhal el 17 de Mayo de 2018
hey, i want to Export the results(Images and Text) of my mfile into a pdf-Report. I did it for the first Test and it works fine. But when i use a Loop to generate many Reports and save them in a Folder it didn't work.The code i could write can be use only for one Report or Image. it should look like this in the folder:
  • report1
  • report2
if true
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('Test','pdf');
tp=TitlePage;
tp.Title = 'Fehlerbericht des BNSE-Tests';
tp.Author = 'Idriss Moffo';
add(rpt,tp);
ch1 = Chapter();
ch1.Title = 'Störszenario: Menuesprung';
sec1 = Section;
sec1.Title = 'Last Image';
imageObj1 = Image(which('A.png'));
imageObj1.Height = '3in';
imageObj1.Width = '5in';
add(sec1,imageObj1);
add(ch1,sec1);
add(rpt,ch1);
close(rpt);
rptview(rpt.OutputPath);
end

Respuestas (1)

Rahul Singhal
Rahul Singhal el 14 de Mayo de 2018
Hi,
From the code it seems that the output report name is always kept the same. So if you generate multiple reports in a loop while keeping the output report name same, the generated report will be overridden in every loop iteration and hence you will see only one PDF report at the end. To fix this, just update the report name in every loop iteration using a counter. Below is a sample code:
% Specify a counter variable before the loop
counter = uint8(0);
% Start of the loop
for a = 1:10
% Your code in the loop
if true
% Your code ....
% Increament the counter and use it to create report name
counter = counter + 1;
rpt_name = strcat('report', int2str(counter));
% Create the report using this report name
rpt = Report(rpt_name,'pdf');
% Rest of the code ....
end
end % End of the loop
  4 comentarios
idriss Moffo
idriss Moffo el 17 de Mayo de 2018
Hey Rahul, thanks for your replies. I solved the Problem using fullfile. Now i will try to implement the Report function that it always check if the Name already exists, such as avoiding overriding when i restart the code. for example: today: report1, report2, report3 tomorrow:...., report4, report5...
Thank you
Rahul Singhal
Rahul Singhal el 17 de Mayo de 2018
See if you can use use persistent counter variable for this use case.
Another alternative is to save the counter variable to a MAT-file using the save command at the end of the day, and then load the updated value from this MAT-file using the load command next day.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by