Azzera filtri
Azzera filtri

How do I control number formatting for 'mlreportgen.ppt.Table' object?

7 visualizzazioni (ultimi 30 giorni)
I want to control number formatting in a 'mlreportgen.ppt.Table' object. If I have a ‘mlreportgen.dom.NumberFormat’ object, I can specify the numbers in the table to have a chosen precision using 'NumberFormat' or 'setDefaultNumberFormat', but I cannot find any way to do this for 'mlreportgen.ppt.Table' object. 
I'd like to use general formatting strings like '%1.2f' or a precision spec from the 'round' function. My source data is in tabular form. How do I accomplish this workflow? 

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 13 Set 2024 alle 0:00
Modificato: MathWorks Support Team il 13 Set 2024 alle 17:47
For ‘mlreportgen.ppt.Table’ objects, one possible way to set number format is to use 'compose' function to format data into multiple strings. Since your source data is in tabular format, you could first use 'table2array' function to convert the tabular data to an array and then use the 'compose' function to convert data to desired number format.
An example is given below:
T = table([1;2;3],[2; 4; 6 ],[3 ; 6 ; 9 ],...      'VariableNames',["One" "Two" "Three"]); % create a table ArrayTable = table2array(T); % convert tabular data to an array formatSpec = '%.2f'; % desired number format StrNum = compose(formatSpec,ArrayTable); % convert data to desired number format StrTable = [T.Properties.VariableNames; StrNum];  % Obtain the original column header FormattedTable = table(StrTable); % convert back to table
You can find more information about 'table2array' function and 'compose' function following the links below: 

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by