主要内容

瓷砖模型图万博1manbetx

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

用图像瓦片创建报告

用一个大图表打开一个模型。

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

创建要拆分为平铺的大型图像文件。

imgFile =[模型“.png”];印刷品(“-dpng”, [“s”模型],imgFile);

创建并打开一个报告。

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

获取页面布局信息。

pageLayout = rpt.Document.CurrentPageLayout;页大小= pageLayout.PageSize;pageMargins = pageLayout.PageMargins;

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

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

确定适合页面的图像平铺大小。最佳的平铺大小是页面大小减去页边距、排水沟、页眉和页脚。另外,调整tile的高度,使标题的宽度为0.5英寸。注意,对于PDF文档,MATLAB报告生成器将一英寸定义为96像素。

dpi=96;units=mlreportgen.utils.units;tileHeight=units.toPixels(pageSize.Height,“决议”dpi)...-单位。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“决议”,新闻部);tileSize=[tileWidth tileHeight];

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

tiles=切片图像(imgFile,[tileWidth tileHeight]);

将磁贴图像添加到报告中。此外,还添加标题以指示磁贴图像相对于整个图像所属的位置。

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

生成并显示报告。

关闭(rpt);rptview (rpt);

定义切片图像局部函数

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

作用imageimage = imageimage (imageimage, imageimage)%读取图像文件并确定行数和列数%瓷砖。注意,图像数据是行为主的,行在其中首先指定%,列是第二列。img = imread (imgFile);imgSize =大小(img);imgRows = imgSize (1);%的形象高度imgCols = imgSize (2);%图像宽度tileNumRows=tileSize(2);%瓷砖高度tileNumCols = tileSize (1);%瓷砖宽度numCols=ceil(imgCols/tileNumCols);numRows=ceil(imgRows/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 >= imgrom) rowEnd = imgrom;结束nTileRows = rowEnd - rowStart + 1; / /开始如果(colEnd >= imgCols) colEnd = imgCols;结束nTileCols = colEnd - colStart + 1;复制平铺图像数据到一个白色图像平铺。tileImg=uint8(255*one(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,outFile);%创建平铺数据结构以描述平铺。Count = Count + 1;瓷砖{数}=结构(...“文件”,outFile,...“行”rowIdx,...“上校”, colIdx);结束结束结束