NumberFormat on specific/few columns - Report Generator

조회 수: 6 (최근 30일)
Ali razi
Ali razi 2022년 1월 26일
댓글: Rahul Singhal 2022년 1월 27일
I am formating a table using this line:
tableData = FormalTable(tableData);
tableData.Border = 'Solid';
tableData.RowSep = 'Solid';
tableData.ColSep = 'Solid';
tableData.Style = [tableData.Style {NumberFormat("%.4f")}];
Is it possible to run the NumberFormat on specific/few columns and not on all the table?

답변 (1개)

Rahul Singhal
Rahul Singhal 2022년 1월 26일
Hi Ali,
You can apply NumberFormat to any specific entry, row, or column in a table. Below are some examples:
%% Apply NumberFormat to a specific entry in the table
entry22 = tableData.entry(2,2);
entry22.Style = [entry22.Style {NumberFormat("%.4f")}];
%% Apply NumberFormat to specific row in the table
row3 = tableData.row(3);
row3.Style = [row3.Style {NumberFormat("%.4f")}];
%% Apply NumberFormat to specific column in the table
colNumber = 1;
for iRow = 1:tableData.NRows
tableEntry = tableData.entry(iRow,colNumber);
tableEntry.Style = [tableEntry.Style {NumberFormat("%.4f")}];
end
Thanks,
Rahul
  댓글 수: 4
Ali razi
Ali razi 2022년 1월 27일
편집: Ali razi 2022년 1월 27일
Thanks a lot it worked.
I also tried to convert the numbers to decimal by replacing to this line:
tableEntry.Style = [tableEntry.Style {NumberFormat("%d")}];
But I go this error:
Error using mlreportgen.dom.NumberFormat
Invalid sprintf value for NumberFormat: %d.
Why?

댓글을 달려면 로그인하십시오.

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by