Azzera filtri
Azzera filtri

Using fprintf to display an existing table

34 visualizzazioni (ultimi 30 giorni)
Michael Boyle
Michael Boyle il 13 Mar 2021
Risposto: Star Strider il 13 Mar 2021
I created a table of data as shown below and want to use fprintf to display it with some text. Is this possible with fprintf or is there another function I need?
T = table(ratio',phi_deg',theta_p',theta_T',c');
T.Properties.VariableNames = {'ratio' 'phi (deg)' 'theta_p (deg)' 'theta_T (deg)' 'c (m)'};
fprintf('\n #3 The table is \n \t %1.2f',T);

Risposte (1)

Star Strider
Star Strider il 13 Mar 2021
I would do something like this:
T = array2table(rand(5));
T.Properties.VariableNames = {'ratio' 'phi (deg)' 'theta_p (deg)' 'theta_T (deg)' 'c (m)'};
fid = 1;
fprintf(fid, ['\t' repmat('%s\t',1,5) '\n'], T.Properties.VariableNames{:})
fprintf(fid, ['\t' repmat('%.4f\t\t',1,5) '\n'], table2array(T).')
Adjust the fprintf statements to give the result you want. (Using 1 for ‘fid’ prints to the Command Window, making all this easier.)

Categorie

Scopri di più su MATLAB 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