我正在嘗試在下面的代碼中生成一個并排顯示兩個影像和一個拆分表的報告,但出現錯誤。為什么會出現這個錯誤?
代碼:
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 = {Width('3.2in'), Height('3in')};*
uj5u.com熱心網友回復:
你定義變數
Height = [1;8;4;7;8;8;3;1;0;4];
然后您嘗試使用報告生成功能 Height
lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};
因為您已經Height用變數遮蔽了函式,所以 MATLAB 試圖在 index 處獲取此陣列的元素,'3in'這要么是荒謬的,要么(通過一些隱式 ASCII 轉換)超出范圍。
根據我對您之前問題的評論,我認為檔案建議匯入報告生成函式的方式是不好的做法。通過使用import mlreportgen.dom.*,您將把該包中所有具有良好名稱空間的函式放入公共區域,在這種情況下,它導致了兩件事之間的不明確沖突。所以有兩種選擇:
使用
Height(andWidth) 的命名空間版本,如果您使用所有報告生成函式執行此操作,則不需要import. 很好的副作用是當你從這個包中輸入各種函式時,你會得到 tab-completionlot.entry(1,1).Style = {mlreportgen.dom.Width('3.2in'), mlreportgen.dom.Height('3in')};當然,您的代碼更長,但更明確。
... 或者 ...
簡單地不要定義一個名為
Height. 重命名它,其他一切都可以保持不變。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/422690.html
標籤:
上一篇:將python'repeat'代碼轉換為Matlab
下一篇:并排影像-MATLAB報告生成器
