Programmatically generating Report Generator

조회 수: 5 (최근 30일)
idriss Moffo
idriss Moffo 2018년 3월 1일
댓글: Rahul Singhal 2018년 5월 17일
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

답변 (1개)

Rahul Singhal
Rahul Singhal 2018년 5월 14일
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
idriss Moffo
idriss Moffo 2018년 5월 17일
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 2018년 5월 17일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Create Report Programs Using the Report API에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by