MATLAB Answers

0

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

  0 Comments

Sign in to comment.

Products


Release

R2019a

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

  0 Comments

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.

  2 Comments

END=[Qt Ht Hbt Wt Tt Pet Pt Nt NPSHdt];
names={'QCau','Hpump','Hsystem','W','T','Pe','P','N','NPSHd'};
T = array2table(END,'VariableNames',names);
T.Properties.VariableUnits = {'m3/s','m','m','rad/s','N*m','W','W','%','m'};
disp(T)
Should I implement it like that? It did not work..
04c47ed2e7ef693186f826d1422c4842.png
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
summary(T)
You'll be able to see the defined units.

Sign in to comment.