How can I add Column and Row Header to 2d formatted data in pdf using MATLAB Report Generator?
6 次查看(过去 30 天)
显示 更早的评论
I have a 2D matrix that I wanted to write in pdf. Following from my first question, I have done forming of data. Now, I want to add a Column and Row header to it.
I have tried to make the Column and Row Header; how can I append values and export them in pdf.
clear all
addpath('hex_and_rgb_v1.1.1')
addpath('colorGradient')
format short
z=[
0 0.5 1;
0.5 0.3 0.33;
0.8 0.9 0.10;
];
import mlreportgen.report.*
import mlreportgen.dom.*
rpt = Report('FormattedTable','pdf');
tb = Table(z); %Data Table
headerStyle={ Border('none'),...
ColSep('none'),...
RowSep('none'),...
HAlign('center') };
dataHeader = {'Good', 'Happy','Best'};
myheader = Table(4);
myheader.Style = [myheader.Style headerStyle];
%t = FormalTable(myheader ,dataHeader);
%add(rpt,t) %This add the string but not in Table format
dataRowHeader = {'Great', 'Amazing','Owsum'};
rowheader = TableRow;
rowheader.Style = [rowheader.Style headerStyle];
p = Paragraph(' ');
p.Style = [p.Style headerStyle {HAlign('center')}];
te = TableEntry(p);
append(rowheader, te);
% Conditional formatting for table entries
nRows = tb.NRows;
nCols = tb.NCols;
for iRow = 1:nRows
for iCol = 1:nCols
entry = tb.entry(iRow,iCol);
entryContent = entry.Children.Content;
% Provide as many cases you want based on the entry content value
if entryContent < 0.5
entry.Style = {BackgroundColor('red')};
else
entry.Style = {BackgroundColor('green')};
end
end
end
tb.Style = {Width('100%'),...
Border('none'),...
ColSep('none'),...
RowSep('none') };
tb.Width= '3in';
tb.TableEntriesVAlign = 'middle';
tb.TableEntriesHAlign = 'center';
%tb.Border = 'single';
add(rpt,tb)
close(rpt)
rptview(rpt)
I tried to append the table with the row header, but it throws an error.
I have seen the code on math work to generate the table. But I didn't make much out of it since I am a bit new to Report Generator.
My final output will be the 2D formatted matrix with both Row and Column Header exported in pdf.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Report Generator 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!