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

5 vues (au cours des 30 derniers jours)
s
s le 5 Mai 2023
Commenté : Atsushi Ueno le 6 Mai 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);

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 5 Mai 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]
  1 commentaire
Atsushi Ueno
Atsushi Ueno le 6 Mai 2023
>変数「Path」で宣言した「test」という名のフォルダに作成したpdfファイルを保存したい場合
どの関数に変数「Path」を組み込めばいいでしょうか。
見直して気付いたので補足訂正致します。
下記では現在のフォルダ下の「testファイル」フォルダに「test.pdf」が作られます。
Path = [pwd filesep 'testファイル/test'] % 適当なパスの例
現在のフォルダ下の「testファイル/test」フォルダに「pdfファイル名.pdf」を作るには下記の様にします。
Path = [pwd filesep 'testファイル/test/pdfファイル名'] % 適当なパスの例
これは絶対パスなので自由な文字ベクトルまたは string スカラーに変更出来ます。(但し当該フォルダの存在とアクセス権が必要です)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Report Generator のタスクの例 dans Help Center et File Exchange

Tags

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!