主要内容

Tile 金宝appSimulink图

此示例展示如何使用跨多个页面的大型图表创建报告。

创建带有图像磁贴的报告

打开带有大图表的模型。

模型=“slreportgen_demo_big_diagram”;open_system(模型);

创建大图像文件分割成瓷砖。

imgFile = [model .“使用”];打印(“-dpng”, (“s”模型],imgFile);

创建并打开一个报告。

要创建Word报表,请将输出类型从“pdf”更改为“docx”。要创建HTML报告,请将“pdf”更改为“HTML”或“HTML -file”%一个多文件或单文件报告。rpt = slreportgen.report.Report(“myreport2”“pdf”);打开(rpt);

获取页面布局信息。

pageLayout = rpt.Document.CurrentPageLayout;pageSize = pageLayout.PageSize;pageMargins = pageLayout.PageMargins;

将页眉和页脚设置为0英寸以最大化空间。

pageMargins。头=“0”;pageMargins。页脚=“0”

确定适合页面的图像平铺大小。最佳的平铺尺寸是页面大小减去页边距、排水沟、页眉和页脚。另外,调整平铺的高度,为标题留出0.5英寸。注意,对于PDF文档,MATLAB Report Generator将1英寸定义为96像素。

Dpi = 96;Units = mlreportgen.utils.units;tileHeight = units.toPixels(pageSize.Height,“决议”dpi)...units.toPixels (pageMargins.Top“决议”dpi)...units.toPixels (pageMargins.Bottom“决议”dpi)...units.toPixels (pageMargins.Header“决议”dpi)...units.toPixels (pageMargins.Footer“决议”dpi)...units.toPixels (“0.5”“决议”, dpi);tileWidth = units.toPixels(pageSize.Width,“决议”dpi)...units.toPixels (pageMargins.Left“决议”dpi)...units.toPixels (pageMargins.Right“决议”dpi)...units.toPixels (pageMargins.Gutter“决议”, dpi);tileSize = [tileWidth tileHeight];

调用sliceImage局部函数(见下文)将大图像文件切片为图像块。

tiles = sliceImage(imgFile, [tileWidth tileHeight]);

将平铺图像添加到报表中。此外,还要添加一个标题,以指示平铺图像相对于整体图像的位置。

I = 1:numel(tiles) tile = tiles{I};formalImage = mlreportgen.report.FormalImage(tile.File);formalImage。ScaleToFit = false;formalImage。标题= sprintf('行:%d, col: %d'瓷砖。行,tile.Col);add (rpt, formalImage);结束

生成并显示报告。

关闭(rpt);rptview (rpt);

定义sliceImage局部函数

若要将图像文件切片为磁片,请读入图像文件并将磁片大小的部分复制到多个图像文件中。

函数tiles = sliceImage(imgFile, tileSize)%在映像文件中读取并确定行数和列数%瓷砖。注意,图像数据是行为主的,即行所在的位置%是第一个,列是第二个。img = imread(imgFile);imgSize = img;imgrew = imgSize(1);图像高度百分比imgCols = imgSize(2);图像宽度%tileNumRows = tileSize(2);瓦高百分比tileNumCols = tileSize(1);瓦宽百分比numCols = cell (imgCols / tileNumCols);numRows = ceil(imgrew / tileNumRows);预分配瓷砖数据结构。tiles = cell(1, numCols*numRows);确定创建平铺图像文件名的基本文件名。[fPath, fName, fExt] = fileparts(imgFile);tileName = fullfile(fPath, fName);遍历所有行和列。计数= 0;rowIdx = 1:numRowscolIdx = 1:numCols确定要复制的开始和结束图像数据索引%放入平铺图像。在边缘,结束指标是行数和列数的%。rowStart = (rowIdx - 1) * tileNumRows + 1;rowEnd = rowStart + tileNumRows - 1;colStart = (colIdx - 1) * tileNumCols + 1;colEnd = colStart + tileNumCols - 1;如果(rowEnd >= imgrew);结束nTileRows = rowEnd - rowStart + 1;如果(colEnd >= imgCols);结束nTileCols = colEnd - colStart + 1;将平铺图像数据复制到白色图像平铺上。tileImg = uint8(255 * ones(tileNumRows, tileNumCols, 3));tileImg(1:nTileRows, 1:nTileCols,:) = img(rowStart:rowEnd,...colStart: colEnd:);写出图像平铺。outFile = sprintf(' % s_ % d_ % d % s ', tileName, rowIdx, colIdx, fExt);imwrite (tileImg输出文件);创建贴图数据结构来描述贴图。Count = Count + 1;Tiles {count} = struct(...“文件”输出文件,...“行”rowIdx,...“上校”, colIdx);结束结束结束