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

조회 수: 16 (최근 30일)
Johnny Birch
Johnny Birch 2019년 2월 8일
답변: Mary Abbott 2019년 3월 13일
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

답변 (1개)

Mary Abbott
Mary Abbott 2019년 3월 13일
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:

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by