Can I add units to the table?

65 visualizaciones (últimos 30 días)
Diego Guarachi
Diego Guarachi el 17 de Mayo de 2019
Editada: dpb el 29 de Jul. de 2024
Can I add units to the variables in the table? I have searched for information and I could not find anything, it can only be done in numbers ...please help
  7 comentarios
Walter Roberson
Walter Roberson el 28 de Jul. de 2024
The units are shown with summary () -- but that is about the limit
Paul
Paul el 28 de Jul. de 2024
Editada: dpb el 29 de Jul. de 2024
Sure, enough. They don't even get checked when co[n]catenating tables.
T1 = table([1;2;3],'VariableNames',{'x'}); T1.Properties.VariableUnits = {'sec'};
T2 = table(2*[1;2;3],'VariableNames',{'x'}); T2.Properties.VariableUnits = {'m'};
summary([T1;T2])
Variables: x: 6x1 double Properties: Units: sec Values: Min 1 Median 2.5 Max 6
summary([T2;T1])
Variables: x: 6x1 double Properties: Units: m Values: Min 1 Median 2.5 Max 6

Iniciar sesión para comentar.

Respuestas (2)

Raj
Raj el 17 de Mayo de 2019
"Can I add units to the variables in the table?" Yes you can. You can specify units for each variable in the table by modifying the table property,
% |VariableUnits|.
Specify the variable units as a cell array of character vectors.
Something like this:
table (W,T,Pe,P)
T.Properties.VariableUnits = {'Rad/S','NM','N','N'}; % what I could make out from your picture. Please correct if wrong.
Or Do you want the units to get displayed on your table? Please be clear.
  9 comentarios
Walter Roberson
Walter Roberson el 15 de Dic. de 2020
table() are not designed for presentation purposes. Report Generator has facilities for better output of tables.
That said, it would seem to me to be a small thing to add the units or the Variable Description information (which might be the original names of the variables.) It could even be made into properties as to whether to display them or not. I don't know why Mathworks has not done this.
table() could also benefit from a per-variable format specification... among other things.
dpb
dpb el 28 de Jul. de 2024
t=array2table([[0:2].',rand(3,1)],'VariableNames',{'Time','Velocity'});
t.Properties.VariableUnits={'sec','mph'}
t = 3x2 table
Time Velocity ____ ________ 0 0.011763 1 0.85573 2 0.24784
Indeed to all...there's already room for them with a blank line just waiting to be used for something besides wasted white space.

Iniciar sesión para comentar.


KSSV
KSSV el 17 de Mayo de 2019
It is not allowed...may be you can use something like this:
varNames = {'Name', 'Age_in_Years'} ;
varTypes = {'string','double'};
s = {'Tom' ; 'Dick' ; 'Hary'} ;
a = [20 ;21; 24] ;
T = table(s,a) ;
T.Properties.VariableNames = varNames

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by