Conditional formatting for MATLAB Report Generator Table

15 views (last 30 days)
I'm generating a report using MATLAB Report Generator and I've created a FormalTable() object and populated it with a m x n cell array of data. I've been trying to conditionally format the cells with no success. I can't seem to find a way to access individual cells of the FormalTable() to set a BackgroundColor property (or any other formatting property). Any style format objects I assign to FormalTable() properties such as TableEntriesStyle or Style set that format globally for the entire table.
The workaround is to rather create a m*n series of Text() objects for which I can individually set format properties based on some condition. The challenge is then aligning those text objects on the page to resemble a table. I cannot seem to find how to set the size and location properties of a text object in order to place it on a page.
Any suggestions on how to create a conditionally formatted table for a MATLAB report?

Answers (1)

Krishnan Ramkumar
Krishnan Ramkumar on 8 Dec 2016
Edited: Krishnan Ramkumar on 8 Dec 2016
You can access individual cell from a Formal Table. A sample example code snippet to access and modify Styles of table entry
import mlreportgen.dom.*;
doc = Document('test');
a = magic(5);
table = FormalTable(a);
table.RowSep = 'Solid'
table.ColSep = 'Solid'
table.Border = 'Solid'
table.Body.entry(1,2).Style = {Color('red')} ;
table.Body.entry(1,1).Style = {BackgroundColor('Green')};
append(doc,table);
close(doc);
rptview(doc.OutputPath);

Categories

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

Community Treasure Hunt

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

Start Hunting!