필터 지우기
필터 지우기

Conditional formatting for MATLAB Report Generator Table

조회 수: 11 (최근 30일)
Dinesh Nandlal
Dinesh Nandlal 2016년 10월 27일
편집: Krishnan Ramkumar 2016년 12월 8일
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?

답변 (1개)

Krishnan Ramkumar
Krishnan Ramkumar 2016년 12월 8일
편집: Krishnan Ramkumar 2016년 12월 8일
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);

Community Treasure Hunt

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

Start Hunting!

Translated by