主要内容

超链接图像

此示例显示如何将图像中的区域定义为超链接。您可以定义超链接,使它们链接到目标网页或导航到同一报表中的其他位置。

导入DOM和报表API包,这样就不必使用长的、完全限定的类名。

进口mlreportgen.dom*进口mlreportgen.report*

创建并打开一个报告。

%要创建HTML报告,请将“pdf”更改为“HTML”或“HTML文件”%分别为多文件或单文件报告。rpt=报告(“myreport”,“pdf”);公开(rpt);

给报告添加一段。

内容="点击子图导航到相应的"+...“三角函数文档。”;添加(摘录,第(内容)段);

为不同的三角函数创建具有多个子图的图形。

figH =图;x = linspace (0, 10);sinePlot =次要情节(3、2、1,“单位”,“像素”)情节(x,sin(x));标题(“Sine:sin(x)”);余弦图=子图(3,2,2,“单位”,“像素”);情节(x,cos(x));标题(“余弦:余弦(x)”);secantPlot =次要情节(2、3、“单位”,“像素”);情节(x, sec (x));标题(“sec: sec (x)”);cosecantPlot =次要情节(3 2 4“单位”,“像素”)图(x,csc(x));标题(“余割:csc(x)”);tangentPlot =次要情节(3 2 5“单位”,“像素”);情节(x,tan(x));标题(“切:棕褐色(x)”);cotangentPlot =次要情节(3 2 6“单位”,“像素”);情节(x,床(x));标题(“余切:cot(x)”);

使用图形报告器获取图形快照。使用DOM形象将快照包括在报告中。

figReporter=数字(“来源”figH,“SnapshotFormat”,“jpg”);imgPath=getSnapshotImage(figReporter,rpt);figImg=Image(imgPath);

在快照上创建一个图像映射,为每个子批创建一个图像区域getCoords函数(在本例末尾定义)获取每个子地块的坐标。子地块图像区域的目标设置为用于创建该子地块的三角函数的文档网页。然后,将快照添加到报告中。

map=ImageMap;sinePlotCoords=getCoords(sinePlot);sinePlotArea=ImageArea(“//www.tatmou.com/help/matlab/ref/sin.html”,...“正弦”,sinePlotCoords);附加(映射,sinePlotArea);cosinePlotCoords=getCoords(cosinePlot);cosinePlotArea=ImageArea("//www.tatmou.com/help/matlab/ref/cos.html",...“余弦”,cosinePlotCoords);附加(地图,cosinePlotArea);secantPlotCoords=getCoords(secantPlot);secantPlotArea=ImageArea("//www.tatmou.com/help/matlab/ref/sec.html",...“割线”,secantPlotCoords);附加(地图,secantPlotArea);cosecantPlotCoords=getCoords(cosecantPlot);cosecantPlotArea=ImageArea("//www.tatmou.com/help/matlab/ref/csc.html",...“csc”,cosecantPlotCoords);附加(地图,cosecantPlotArea);tangentPlotCoords=getCoords(tangentPlot);tangentPlotArea=ImageArea("//www.tatmou.com/help/matlab/ref/tan.html",...“切”,tangentPlotCoords);附加(贴图,tangentPlotArea);cotangentPlotCoords=getCoords(cotangentPlot);cotangentPlotArea=ImageArea(“//www.tatmou.com/help/matlab/ref/cot.html”,...“余切”, cotangentPlotCoords);追加(地图,cotangentPlotArea);figImg。地图=地图;add (rpt, figImg);

删除图形窗口。关闭并查看报告。

关闭(rpt);删除(figH);rptview(rpt);

以下函数计算并返回其父图形中指定子地块的左上角和右下角坐标。这些坐标是通过将子地块轴坐标(基于地物坐标系,其参考点为左下角)转换为DOM来计算的ImageArea坐标系,其参考点位于图像的左上角。

函数coords=getCoords(subplot)subplotWidth=subplot.Position(3);subplotHeight=subplot.Position(4);figHeight=fig.Position(4);x1=subplot.Position(1);y1=figHeight-(subplot.Position(2)+subplotHeight);x2=x1+subplotWidth;y2=y1+subplotHeight;coords=[x1,y1,x2,y2];结束