MATLAB Answers


Can I add units to the table?

Asked by Diego Guarachi on 17 May 2019
Latest activity Commented on by Raj
on 17 May 2019
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


Sign in to comment.




2 Answers

Answer by KSSV
on 17 May 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


Sign in to comment.

Answer by Raj
on 17 May 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.


END=[Qt Ht Hbt Wt Tt Pet Pt Nt NPSHdt];
T = array2table(END,'VariableNames',names);
T.Properties.VariableUnits = {'m3/s','m','m','rad/s','N*m','W','W','%','m'};
Should I implement it like that? It did not work..
That's what i asked. The units have got defined. They don't get displayed by default here. If you open the table in workspace, the first row will have a drop down option where you will be able to see the units for each variable as you have defined. Or try using
You'll be able to see the defined units.

Sign in to comment.