Using fprintf to display an existing table

46 vues (au cours des 30 derniers jours)
Michael Boyle
Michael Boyle le 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);

Réponses (1)

Star Strider
Star Strider le 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.)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by