Borrar filtros
Borrar filtros

Using fprintf to display an existing table

34 visualizaciones (últimos 30 días)
Michael Boyle
Michael Boyle el 13 de Mzo. de 2021
Respondida: Star Strider el 13 de Mzo. de 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);

Respuestas (1)

Star Strider
Star Strider el 13 de Mzo. de 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.)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by