Using fprintf to display an existing table

36 ビュー (過去 30 日間)
Michael Boyle
Michael Boyle 2021 年 3 月 13 日
回答済み: Star Strider 2021 年 3 月 13 日
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);

回答 (1 件)

Star Strider
Star Strider 2021 年 3 月 13 日
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.)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by