If I have a pandas.DataFrame in python I can inspect the data types for the DataFrame with the dtypes attribute. How can I do the same with a Matlab table? I poked around the Properties mechanism but didn't find anything type oriented there.
2 Answers
It appears that you can call the following:
varfun(@class,t,'OutputFormat',table)
class_var1 class_var2 class_var3 class_var4
__________ __________ __________ __________
double double double double
where t is your table. I am referencing the answer here.
Further documentation on varfun is available here as well.
2 Comments
jxramos
Nice find, its choking on my particular table, but I think because it has some nested matrix type or something. When I inspect it in the DataInspector there are some "merged" columns for some of the variables, eg variable 2 spans 4 columns:
class(t) ; ans = 'table'; varfun(@class,t,'OutputFormat',cell) ; Error using cell Not enough input arguments.Cris Luengo
@jxramos: If you want to find the class for an individual column, you can also simply say
class(t.var1).Looks like one way to get this information (while unfortunately getting a bunch of other things) is with a simple call to summary.
Here's some sample output
K>> summary(t)
Variables:
var1: 2966185×1 double
Units: sec
Values:
Min 56.207
Median 7466.7
Max 14878
var2: 2966185×4 double
Values:
var2_1 var2_2 var2_3 var2_4
________ __________ ________ ________
Min -0.99966 -0.99901 -0.99887 -0.99998
Median 0.01644 -0.0044018 0.12838 0.1564
Max 0.98176 0.96433 0.99998 1
var3: 2966185×3 double
Units: g
Values:
var3_1 var3_2 var3_3
__________ _________ __________
Min -2.779 -3.1366 -3.6089
Median -0.0002124 -0.002221 -0.0020435
Max 3.7874 5.9634 2.8443
var4: 2966185×1 double
Values:
Min 0
Median 5
Max 5
VariableTypes? mathworks.com/help/matlab/ref/table.html.tab completion after Properties I get presented withDescription,DimensionNames,RowNames,UserData,VariableContinuity,VariableDescriptions,VariableNames, andVariableUnits. I'm in Matlab 2018a. Upon reading the doc it seems VariableTypes is an input string to coerce a data type.tableof a certain type. But that's a different operation too. I'm trying to do something more introspective than something selective.