How can I change the background color of a cell in report generator?

13 visualizaciones (últimos 30 días)
Johnny Birch
Johnny Birch el 8 de Feb. de 2019
Respondida: Mary Abbott el 13 de Mzo. de 2019
I am very new in the report generator toolbox, but hopefully someone can help me here
I am generating a table via report generator, but if i have this table:
T = [1 2 6; 3 4 10; 2 5 10]
is it possible to color the cell so values <10 turns green, >10 & <20 turns yellow, and >20 turns red in the output report?
Thanks a lot in advance

Respuestas (1)

Mary Abbott
Mary Abbott el 13 de Mzo. de 2019
You can change how a particular number is formatted in a table by setting properties of a Text object that contains the number. For example, the following code creates a Text object for an entry in T and sets the BackgroundColor property to green. It creates a table using the Text object and the remaining numbers in T:
% Make T a cell array so that we can replace a number with a Text object
T = {1 2 6; 3 4 10; 2 5 10};
% Replace the number 6 with a Text object
textObj = mlreportgen.dom.Text(T{1,3});
textObj.BackgroundColor = "green";
T{1,3} = textObj;
% Create a Table from the Text objects and add to a report
tbl = mlreportgen.dom.Table(T);
More information about the mlreportgen.dom.Text class along with other formatting options can be found at the following link:

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by