并排报告两个图像和一个拆分 table - Matlab

Report with side by side two images and a splited table - Matlab

我正在尝试在下面的代码中生成包含并排两张图像和拆分 table 的报告,但出现错误。为什么会出现这个错误?

代码:

close all;
clear all;
clc;

import mlreportgen.report.*
import mlreportgen.dom.*
import mlreportgen.utils.*

Name = {'A';'B';'C';'D';'E';'A';'B';'C';'D';'E'};
codeA = [8;3;8;0;4;8;3;8;0;4];
Height = [1;8;4;7;8;8;3;1;0;4];
Weight = [6;2;1;4;5;8;3;1;1;4];
T = table(Name,codeA,Height,Weight,codeA,Height,Weight,codeA,Height,Weight);

Image1 = Image(which('coins.png'));
Image2 = Image(which('sevilla.jpg'));

rpt = Report("myPDF","pdf");
  
imgStyle = {ScaleToFit(true)};
Image2.Style = imgStyle;
Image1.Style = imgStyle;

lot = Table({Image2, ' ', Image1});

lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};
lot.entry(1,2).Style = {Width('.2in'), Height('3in')};
lot.entry(1,3).Style = {Width('3.2in'), Height('3in')};
lot.Style = {ResizeToFitContents(false), Width('100%')};
add(rpt, lot);
 
chapter = Chapter("Title",'Table Report');
table = FormalTable(T);
table.Border = 'Solid';
table.RowSep = 'Solid';
table.ColSep = 'Solid';

para = Paragraph(['The table is sliced into two tables, '...
    'with the first column repeating in each table.']);
para.Style = {OuterMargin('0in','0in','0in','12pt')};
para.FontSize = '14pt';
add(chapter,para)

slicer = TableSlicer("Table",table,"MaxCols",5,"RepeatCols",1);
totcols = slicer.MaxCols - slicer.RepeatCols;
slices = slicer.slice();
for slice=slices
    str = sprintf('%d repeating column and up to %d more columns',...
        slicer.RepeatCols,totcols);
    para = Paragraph(str);
    para.Bold = true;
    add(chapter,para)
    add(chapter,slice.Table)
end

add(rpt,chapter)
close(rpt)
rptview(rpt)

错误:

*索引超出了数组元素的数量。索引不得超过 10。

try1 错误(第 26 行)

lot.entry(1,1).Style = {宽度('3.2in'), 高度('3in')};*

你定义变量

Height = [1;8;4;7;8;8;3;1;0;4];

然后你尝试使用报告生成功能Height

lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};

因为您用变量隐藏了 Height 函数,MATLAB 试图在索引 '3in' 处获取此数组的元素,这要么是无意义的,要么(通过一些隐式 ASCII 转换) 超出范围。

根据我的 ,我认为文档建议导入报告生成函数的方式是不好的做法。通过使用 import mlreportgen.dom.* ,您将该包中所有很好的 name-spaced 函数都放到了公共区域,在这种情况下,它导致了两件事之间的不明确冲突。所以有两种选择:

  1. 使用 Height(和 Width)的命名空间版本,如果您使用所有报告生成函数执行此操作,则不需要 import .好的 side-effect 是你在输入这个包中的各种函数时得到 tab-completion

    lot.entry(1,1).Style = {mlreportgen.dom.Width('3.2in'), mlreportgen.dom.Height('3in')};
    

    当然,你的代码更长,但更明确。

    ...或...

  2. 干脆不要定义一个叫做Height的变量。重命名此名称,其他一切都可以保持不变。