主要内容

创建报表生成器

此示例显示如何创建一个简单的报告,该报告解释并说明了列,行和对角线的列,行和对角线的矩阵均添加到相同的数字。看魔法

笔记

完成逐步指令后包含完整的示例代码。

  1. 导入基类。

    为了消除使用Report和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);

    标题页标题为“Magic Squares”,subtitle“列,行,对角线:所有等金属”,作者“Albrecht Dureer”以及日期

    要自定义其他标题页属性,请参阅mlreportgen.report.titlepage.

  4. 添加一个目录。

    将默认目录对象添加到报告中。

    附录(RPT,TableofContents);

    列出三章的内容表:“介绍”,“10到10魔方”,以及“25乘25魔方”

    要自定义内容表,请参阅mlreportgen.report.tableofContents.

  5. 添加一个章节和章节。

    为简介创建章节对象并指定章节标题。添加一个部分,将段落添加到该部分,并将该部分添加到本章。创建另一部分并添加段落。

    ch1 =章节;ch1.title ='介绍';sec1 =部分;sec1.title ='什么是魔法广场?';para =段落(['魔术方是从整数1到n ^ 2'...'构造的n个vir-n矩阵'...,具有相等的行,列和对角线。');附录(sec1,para)附录(ch1,sec1)sec2 =部分;sec2.title ='albrecht dureer和magic square';Para =段([...'德国艺术家Albrecht Dure(1471-1528)创建了“...”许多木刻和与宗教和“...”科学象征主义的印刷。他最着名的作品之一'..。'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.chere.mlreportgen.report.section.分别。

  6. 添加一个数字。

    在图形窗口中创建杜尔的图像。在MATLAB图中创建图像。将图形添加到“第二部分”章节,然后将章节添加到报告中。

    dureerimage = load(哪个('durematmat'),' -  mat');图('单位','像素','位置',... [200 200尺寸(durerimage.x,2)*。5 ...尺寸(durerimage.x,1)*。5]);图像(durerimage.x);Colormap(dureerimage.map);轴('图像');SET(GCA,'XTICK',[],'YTICK',[],...'单位','普通','位置',[0 0 1 1]);附加(秒,图)附加(RPT,CH1)关闭GCF

    雕刻,“Melancholia I”由Albrecht DuRer

    有关数字的更多信息,请参阅mlreportgen.report.figure.。有关图像的更多信息,请参阅mlreportgen.report.formalimage.

  7. 添加表格。

    添加另一章对象并指定其标题。指定MATLAB代码以创建一个10×10魔方。将结果添加到表并设置这些表属性:

    • 行和列分隔符

    • 表格边框

    • 表条目的对齐

    然后,将表添加到章节和章节中的报告。

    ch2 =章节();ch2.title = sprintf('10 x 10 magic square');广场=魔术(10);TBL =桌(方形);tbl.style = {... Rowsep('solid','black','1px'),... colsep('solid','black','1px'),};tbl.border ='double';tbl.tableentriesttyle = {halign('center')};附加(CH2,TBL);附录(RPT,CH2);

    第2章具有10个魔术广场的标题10,并包含包含魔术广场的边界表。

    有关表的详细信息,请参阅mlreportgen.dom.table.

  8. 将MATLAB图添加到章节。

    添加另一章对象并指定其标题。指定MATLAB代码以创建一个25×25的魔方广场和魔方的颜色编码图。然后,创建图形对象并设置其高度,宽度和标题。将图形添加到章节和章节中的报告。

    ch3 =章节();ch3.title = sprintf('25 x 25魔方');广场=魔术(25);CLF;ImagesC(Square)Set(GCA,'YDIR','正常')轴等轴紧密无图=图(GCF);fig.snapshot.height ='4in';fig.snapshot.width ='6in';fig.snapshot.caption = sprintf('25 x 25 magic square');附加(CH3,图);附录(RPT,CH3); delete(gcf)

    第3章将标题25乘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);附录(RPT,TableofContents);ch1 =章节;ch1.title ='介绍';sec1 =部分; 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)

也可以看看