Zebra-Striped Table in app desginer

1 visualización (últimos 30 días)
Lluis Roca
Lluis Roca el 10 de Mayo de 2020
Respondida: Mary Abbott el 22 de Mayo de 2020
I created this theoretical table (code attached) in order to style it as Zebra-Striped Table. I looked on the example https://www.mathworks.com/help/rptgen/ug/create-a-zebra-striped-table.html but I get this error:
Unrecognized method, property, or field 'row' for class 'mlreportgen.dom.MATLABTable'.
Therefore, how can I fix it? Furthermore, is there a better way to split the table into two, use zebra style and add space between them?
Code:
function ButtonPushed(app, event)
import mlreportgen.dom.*;
import mlreportgen.report.*
ID = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20];
Name = {'San';'John';'Lee';'Boo';'Jay';'Li';'Jo';'Tom,';'Mike';'Dave,';'San';'John';'Lee';'Boo';'Jay';'Li';'Jo';'Tom,';'Mike';'Dave,'};
r1 = rot90(randi([0 10],1,20));
r2 = rot90(randi([-20 10],1,20));
r3 = rot90(randi([0 9],1,20));
r4 = rot90(randi([0 10],1,20));
r5 = (-5 + (5+5)*rand(20,1));
r6 = (5 + (5+5)*rand(20,1));
r7 = (5 + (5+5)*rand(20,1));
r8 = rot90(randi([0 100],1,20));
t = table(ID,Name,r1, r2, r3, r4, r5,r6,r7, r8);
ta1 = (t(:,[1 2 3 4 5]));
ta2 = (t(:,[1 6 7 8 9 10]));
sTable1 = MATLABTable(ta1);
sTable2 = MATLABTable(ta2);
headerStyle = { BackgroundColor("Yellow"), Bold(true), Italic(true) };
set(sTable1, 'Width', '100%', 'Border', 'single',...
'RowSep', 'solid', 'ColSep', 'solid',...
'TableEntriesHAlign', 'center');
set(sTable2, 'Width', '100%', 'Border', 'single',...
'RowSep', 'solid', 'ColSep', 'solid',...
'TableEntriesHAlign', 'center');
sTable1.HeaderRule = '';
sTable1.Header.Style = headerStyle;
sTable2.HeaderRule = '';
sTable2.Header.Style = headerStyle;
p1 = Paragraph(' ');
p1.Style = {OuterMargin('0.5in','0in','0in','12pt')};
d = Document('myPDF','pdf');
d.OutputPath = ['E:/','ReportPDF'];
for i = 1:height(ta1)
r = sTable1.row(i);
if mod(i,2)==0
sTable1.Style = {BackgroundColor('lightsteelblue')};
else
sTable1.Style = {BackgroundColor('white')};
end
end
sTable1.Style={RowHeight('0.3in'),RowSep('solid'),ColSep('solid')};
sTable1.Width= '3in';
sTable1.TableEntriesVAlign = 'middle';
sTable1.TableEntriesHAlign = 'center';
sTable1.Border = 'single';
append(d,sTable1);
append(d,p1);
append(d,sTable2);
close(d);
rptview(d.OutputPath);
end
end

Respuestas (1)

Mary Abbott
Mary Abbott el 22 de Mayo de 2020
Hi Lluis,
The example uses the mlreportgen.dom.Table class, which has a row method to access specific rows of the table. The error is occuring because you are using the class mlreportgen.dom.MATLABTable class, which does not have the row method. To create a zebra-striped MATLABTable, use the row method of the table's Body property.
for i = 1:height(ta1)
r = sTable1.Body.row(i);
if mod(i,2)==0
r.Style = {BackgroundColor('lightsteelblue')};
else
r.Style = {BackgroundColor('white')};
end
end

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by