Report Generator で作成したpdfファ​イルを特定のパスで指​定したフォルダに保存​する方法

4 views (last 30 days)
s
s on 5 May 2023
Commented: s on 9 May 2023
Matlabの「Report Generator」で作成したpdfファイルをMatlabで現在開いているフォルダでなく、
指定したパスのフォルダ内に保存したいです。
「Report Generator」を使ったことがなく、初心者で以下の公式ページを参考にしながらpdfファイルを作っています。
(公式ページ:https://jp.mathworks.com/help/rptgen/ug/create-a-landscape-report.html)
以下の公式のコード例では、変数「Path」で宣言した「test」という名のフォルダに作成したpdfファイルを保存したい場合
どの関数に変数「Path」を組み込めばいいでしょうか。特に指定しない場合は、現在のフォルダーに保存されます。
お手数をおかけしますが、教えていただけますと、幸いです。
%pdfファイルを保存したパス
Path = "testファイル/test"
% 公式ページのコード例(https://jp.mathworks.com/help/rptgen/ug/create-a-landscape-report.html)
import mlreportgen.dom.*;
import mlreportgen.report.*;
rpt = Report("figureSnapshotSideBySideLandscape","pdf");
rpt.Layout.Landscape = true;
chapter = Chapter("Title", "Types of Cosine Value Plots with Random Noise");
x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);
imgStyle = {ScaleToFit(true)};
fig1 = Figure(bar(x, y));
fig1Img = Image(getSnapshotImage(fig1, rpt));
fig1Img.Style = imgStyle;
delete(gcf);
fig2 = Figure(scatter(x,y));
fig2Img = Image(getSnapshotImage(fig2, rpt));
fig2Img.Style = imgStyle;
delete(gcf);
fig3 = Figure(plot(x,y));
fig3Img = Image(getSnapshotImage(fig3, rpt));
fig3Img.Style = imgStyle;
delete(gcf);
lo_table = Table({fig1Img, ' ', fig2Img, ' ',fig3Img});
lo_table.entry(1,1).Style = {Width('3.2in'), Height('3in')};
lo_table.entry(1,2).Style = {Width('.2in'), Height('3in')};
lo_table.entry(1,3).Style = {Width('3.2in'), Height('3in')};
lo_table.entry(1,4).Style = {Width('.2in'), Height('3in')};
lo_table.entry(1,5).Style = {Width('3in'), Height('3in')};
add(chapter, lo_table);
add(rpt, chapter);
chapter1 = Chapter("Title", "Surface Plot");
fig4 = Figure(surf(peaks(20)));
fig4Img = Image(getSnapshotImage(fig4, rpt));
fig4Img.Style = imgStyle;
delete(gcf);
add(chapter1, fig4Img);
add(rpt, chapter1);
close(rpt);
rptview(rpt);

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 5 May 2023
mlreportgen.report.Report クラス のプロパティ OutputPath を設定します。拡張子は別途 Type に設定します。
%pdfファイルを保存したパス
Path = [pwd filesep 'testファイル/test'] % 適当なパスの例
Path = '/users/mss.system.ZKGKZJ/testファイル/test'
rpt = mlreportgen.report.Report(Path,"pdf") % 方法1: Reportメソッドの第1引数 OutputPath を設定
rpt =
Report with properties: OutputPath: '/users/mss.system.ZKGKZJ/testファイル/test' Type: "pdf" PackageType: [] TemplatePath: [] Locale: [] Debug: 0 Layout: [1×1 mlreportgen.report.ReportLayout] Document: [0×0 mlreportgen.dom.Document] Context: [0×1 containers.Map]
rpt.OutputPath = Path % 方法2: 作成したrptオブジェクトの OutputPath プロパティを設定
rpt =
Report with properties: OutputPath: '/users/mss.system.ZKGKZJ/testファイル/test' Type: "pdf" PackageType: [] TemplatePath: [] Locale: [] Debug: 0 Layout: [1×1 mlreportgen.report.ReportLayout] Document: [0×0 mlreportgen.dom.Document] Context: [0×1 containers.Map]
  2 Comments
s
s on 9 May 2023
毎度毎度ご丁寧にありがとうございます。助かりました。どうもありがとうございます。

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!