Programmatically generating Report Generator

5 Ansichten (letzte 30 Tage)
idriss Moffo
idriss Moffo am 1 Mär. 2018
Kommentiert: Rahul Singhal am 17 Mai 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

Antworten (1)

Rahul Singhal
Rahul Singhal am 14 Mai 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 Kommentare
idriss Moffo
idriss Moffo am 17 Mai 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 am 17 Mai 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by