主要内容

このページの翻訳は最新ではありません。ここをクリックして,英語の最新版を参照してください。

报告生成器の作成

この例では,魔方陣を説明し図解する単純なレポートの作成方法を示します。魔方陣とは、列、行および対角のいずれについても,合計が同じ数字になる行列です。魔法を参照してください。

メモ

完全なコードの例は,詳細な手順の後に含まれます。

  1. 基底クラスをインポートします。

    レポートAPIオブジェクトとDOM APIオブジェクトの完全修飾名を使用する必要をなくすには,次のステートメントを使用します。たとえば,mlreportgen.report.Reportを使用する代わりに,报告を使用できます。

    进口mlreportgen.report。*进口mlreportgen.dom。*
  2. レポートオブジェクトを作成します。

    レポートオブジェクトを作成します。ファイル名として“魔法”を,レポートのタイプとして“html”を使用します。

    rpt =报告(“魔法”、“html”);

    レポート全体に適用されるプロパティをカスタマイズするには,mlreportgen.report.Reportを参照してください。

  3. タイトルページを追加します。

    タイトルページを作成して,ページのタイトル,サブタイトル,作成者を指定します。その後,タイトルページをレポートに追加します。

    tp = TitlePage;tp。Title = '魔法方块';tp。Subtitle = '列,行,对角线:所有相等的和';tp。Author = 'Albrecht Durer';追加(rpt, tp);

    标题页“魔术方块”,副标题“列,行,对角线:所有相等的总和”,作者“Albrecht Durer”,和日期

    タイトルページのプロパティをさらにカスタマイズするには,mlreportgen.report.TitlePageを参照してください。

  4. 目次を追加します。

    既定の目次オブジェクトをレポートに追加します。

    追加(rpt TableOfContents);

    内容表列出了三章:“导论”、“10 × 10魔方”和“25 × 25魔方”

    目次をカスタマイズするには,mlreportgen.report.TableOfContentsを参照してください。

  5. 章と節を追加します。

    序章の章オブジェクトを作成して,章タイトルを指定します。節を追加し,節に段落を追加して,節を章に追加します。別の節を作成して,節に段落を追加します。

    ch1 =章;ch1。Title =“介绍”;sec1 =节;sec1。Title = '什么是魔方?';para = Paragraph(['A magic square is an n × n matrix '…'从整数1到N^2 '…'具有相等的行、列和对角线和']);append(sec1,para) append(ch1,sec1) sec2 = Section; sec2.Title = 'Albrecht Durer and the Magic Square'; para = Paragraph([ ... 'The German artist Albrecht Durer (1471-1528) created '... 'many woodcuts and prints with religious and '... 'scientific symbolism. One of his most famous works, '... 'Melancholia I, explores the depressed state of mind '... 'which opposes inspiration and expression. '... 'Renaissance astrologers believed that the Jupiter '... 'magic square (shown in the upper right portion of '... 'the image) could aid in the cure of melancholy. The '... 'engraving''s date (1514) can be found in the '... 'lower row of numbers in the square.']); append(sec2,para) append(ch1,sec2)

    第一章,分为“什么是魔方”和“阿尔布莱希特丢勒和魔方”两部分

    章と節のカスタマイズの詳細については,mlreportgen.report.Chaptermlreportgen.report.Sectionをそれぞれ参照してください。

  6. 图を追加します。

    图ウィンドウでデューラーのイメージを作成します。MATLAB图でイメージを作成します。この图を序章の第2節に追加し,この章をレポートに追加します。

    durerImage =负载((“durer.mat”),“垫”);图(“单位”,“像素”、“位置”,…200年[200大小(durerImage.X, 2) *。5……大小(durerImage.X 1) *。5);图像(durerImage.X);colormap (durerImage.map);轴('图像');集(gca、“Xtick”,[],“Ytick”,[],…'Units','normal','Position',[0 0 1 1]);append(rpt,ch1) close gcf

    版画:Albrecht Durer的《忧郁症I》

    图の詳細については,mlreportgen.report.Figureを参照してください。イメージの詳細については,mlreportgen.report.FormalImageを参照してください。

  7. テーブルを追加します。

    もう1つ章オブジェクトを追加して,タイトルを指定します。10行10列の魔方陣を作成するMATLABコードを指定します。結果をテーブルに追加して,次のテーブルプロパティを設定します。

    • 行と列の区切り

    • テーブルの境界線

    • テーブルエントリの配置

    次に,テーブルを章に追加し,章をレポートに追加します。

    ch2 =(章);ch2。Title = sprintf('10 x 10 Magic Square');平方=魔法(10);台=表(广场);资源描述。风格={…RowSep(“固体”、“黑色”,“1 px”),…ColSep(“固体”、“黑色”,“1 px”),};资源描述。Border = 'double'; tbl.TableEntriesStyle = {HAlign('center')}; append(ch2,tbl); append(rpt,ch2);

    第二章的标题是10乘10的魔方,包含一个包含魔方的带边框的表格。

    テーブルの詳細については,mlreportgen.dom.Tableを参照してください。

  8. MATLAB图を章に追加します。

    もう1つ章オブジェクトを追加して,タイトルを指定します。25行25列の魔方陣と色分けされた魔方陣の图を作成するMATLABコードを指定します。次に,图オブジェクトを作成して,その高さ,幅,および表題を設定します。图を章に追加し,章をレポートに追加します。

    甲基=(章);甲基。Title = sprintf('25 x 25魔术方块');平方=魔法(25);clf;imagesc(square) set(gca,'Ydir','normal') axis equal axis tight图=图(gcf);fig.Snapshot.Height =“4”;fig.Snapshot.Width = ' 6 ';fig.Snapshot.Caption = sprintf('25 x 25 Magic Square');追加(ch3、无花果); append(rpt,ch3); delete(gcf)

    第3章的标题是25 × 25魔术方块,包含了一个用颜色编码的魔术方块图形。

    图の詳細については,mlreportgen.report.Figureを参照してください。

  9. レポートを閉じて実行します。

    关上(rpt) rptview (rpt)

完全なコードは次のとおりです。

进口mlreportgen.report。*进口mlreportgen.dom。*rpt =报告(“魔法”、“html”);tp = TitlePage;tp。Title = '魔法方块';tp。Subtitle = '列,行,对角线:所有相等的和';tp。Author = 'Albrecht Durer';追加(rpt, tp); append(rpt,TableOfContents); ch1 = Chapter; ch1.Title = 'Introduction'; sec1 = Section; sec1.Title = 'What is a Magic Square?'; para = Paragraph(['A magic square is an N-by-N matrix '... 'constructed from the integers 1 through N^2 '... 'with equal row, column, and diagonal sums.']); append(sec1,para) append(ch1,sec1) sec2=Section; sec2.Title = 'Albrecht Durer and the Magic Square'; para = Paragraph([ ... 'The German artist Albrecht Durer (1471-1528) created '... 'many woodcuts and prints with religious and '... 'scientific symbolism. One of his most famous works, '... 'Melancholia I, explores the depressed state of mind '... 'which opposes inspiration and expression. '... 'Renaissance astrologers believed that the Jupiter '... 'magic square (shown in the upper right portion of '... 'the image) could aid in the cure of melancholy. The '... 'engraving''s date (1514) can be found in the '... 'lower row of numbers in the square.']); append(sec2,para) append(ch1,sec2) durerImage=load(which('durer.mat'),'-mat'); figure('Units','Pixels','Position',... [200 200 size(durerImage.X,2)*.5 ... size(durerImage.X,1)*.5 ]); image(durerImage.X); colormap(durerImage.map); axis('image'); set(gca,'Xtick',[],'Ytick',[],... 'Units','normal','Position',[0 0 1 1]); append(sec2,Figure) append(rpt,ch1) close gcf ch2 = Chapter(); ch2.Title = sprintf('10 x 10 Magic Square'); square = magic(10); tbl = Table(square); tbl.Style = {... RowSep('solid','black','1px'),... ColSep('solid','black','1px'),}; tbl.Border = 'double'; tbl.TableEntriesStyle = {HAlign('center')}; append(ch2,tbl); append(rpt,ch2); ch3 = Chapter(); ch3.Title = sprintf('25 x 25 Magic Square'); square = magic(25); clf; imagesc(square) set(gca,'Ydir','normal') axis equal axis tight fig = Figure(gcf); fig.Snapshot.Height = '4in'; fig.Snapshot.Width = '6in'; fig.Snapshot.Caption = sprintf('25 x 25 Magic Square'); append(ch3,fig); append(rpt,ch3); delete(gcf) close(rpt) rptview(rpt)

参考