
Format of numeric values in Disp command
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a display command of form pasted below. The u1star values are printed as #.####e-109. I just want these numbers printed to 4 decimal places and not to use the e-## format. How do i use the commands below to achieve this? Thank you.
T=table(results(:,1), results(:,2), results(:,3), ...
results(:,4), results(:,5), results(:,6));
header={'u2_fixed', 'x_initial', 'u1_initial', 'xstar', 'u1star', 'ystar'};
T.Properties.VariableNames = header;
disp(T);
1 comentario
Star Strider
el 3 de Feb. de 2020
Tables inherit the current format setting from the environment, so changing that can change the wasy table clements are displayed. However with extremely large or small values (such as something on the order of
I doubt there is much you can do about that, unless you sant to display them as 0.0000 or some such. Experiment with the format setting and see what works for you.

Respuestas (4)
Joe Apaloo
el 3 de Feb. de 2020
Editada: Walter Roberson
el 3 de Feb. de 2020
1 comentario
Walter Roberson
el 3 de Feb. de 2020
Are all the columns in the table numeric? If so then the round() command I showed should work, provided that you are not using too old of a MATLAB.
>> T = array2table(rand(10,5))
T =
10×5 table
Var1 Var2 Var3 Var4 Var5
__________________ __________________ _________________ __________________ _________________
0.609866648422558 0.167927145682257 0.096730025780867 0.453797708726919 0.399257770613576
0.617666389588455 0.978680649641159 0.818148553859625 0.432391503783462 0.526875830508296
0.859442305646212 0.712694471678914 0.817547092079286 0.825313795402046 0.416799467930787
0.805489424529686 0.500471624154843 0.722439592366842 0.083469814858914 0.656859890973707
0.576721515614685 0.471088374541939 0.149865442477967 0.133171007607162 0.627973359190104
0.182922469414914 0.0596188675796392 0.659605252908307 0.173388613119006 0.291984079961715
0.239932010568717 0.681971904149063 0.518594942510538 0.390937802323736 0.43165117024872
0.886511933076101 0.0424311375007417 0.972974554763863 0.83137974283907 0.015487125636019
0.0286741524641061 0.0714454646006424 0.648991492712356 0.80336439160244 0.984063724379154
0.489901388512224 0.521649842464284 0.800330575352401 0.0604711791698936 0.167168409914656
>> round(T{:,:},4)
ans =
0.6099 0.1679 0.0967 0.4538 0.3993
0.6177 0.9787 0.8181 0.4324 0.5269
0.8594 0.7127 0.8175 0.8253 0.4168
0.8055 0.5005 0.7224 0.0835 0.6569
0.5767 0.4711 0.1499 0.1332 0.628
0.1829 0.0596 0.6596 0.1734 0.292
0.2399 0.682 0.5186 0.3909 0.4317
0.8865 0.0424 0.973 0.8314 0.0155
0.0287 0.0714 0.649 0.8034 0.9841
0.4899 0.5216 0.8003 0.0605 0.1672
Joe Apaloo
el 3 de Feb. de 2020
1 comentario
Walter Roberson
el 3 de Feb. de 2020
Unless results was a cell array, round(T{:,:},4) will work.
Note that using that will not modify T and will not affect what you see with the variable browser -- but your question was about what is seen with disp() not about the variable browser and not about storing the rounded versions.
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!