include an m file in a report

8 ビュー (過去 30 日間)
Jon Brown
Jon Brown 2020 年 2 月 5 日
コメント済み: Jon Brown 2020 年 2 月 5 日
I would like to be able to include code contained in an m-file in a pdf report created with the Report Generator. I know I can use 'publish', to do this but I want to make use of the other functionality of report. Is this possible?
import mlreportgen.report.*
import mlreportgen.dom.*
R = Report('test','pdf');
open(R)
% add code from a separate M-file (eg 'script.m')
close(R)

採用された回答

Mary Abbott
Mary Abbott 2020 年 2 月 5 日
Hello,
To display the contents of an M file in a Report Generator report, you can use an mlreportgen.dom.Text object to contain the text. Set the style of the Text object to look more like preformatted code:
import mlreportgen.dom.*
fileText = fileread('script.m');
textObj = Text(fileText);
% Set text object to preserve whitespace and use a monospace font
textObj.Style = {WhiteSpace('preserve'), FontFamily('Courier New')};
add(R, textObj);
Note: This will display the correct indentation in the M file, but will not display any syntax highlighting or evaluate code in the M file.
  1 件のコメント
Jon Brown
Jon Brown 2020 年 2 月 5 日
Thank you! That's very useful.
I guess there is no way of maintaining the syntax highlighting?

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by