Using fprintf to display an existing table

46 views (last 30 days)
Michael Boyle
Michael Boyle on 13 Mar 2021
Answered: Star Strider on 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);

Answers (1)

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

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!