How can I add Column and Row Header to 2d formatted data in pdf using MATLAB Report Generator?

3 views (last 30 days)
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.

Answers (0)

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!