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.
Asked
Active
Viewed 3,997 times
4

jxramos
- 7,356
- 6
- 57
- 105
-
Isn't there a Property called `VariableTypes`? https://www.mathworks.com/help/matlab/ref/table.html – rahlf23 Oct 01 '18 at 20:12
-
If I try a `.` tab completion after Properties I get presented with `Description`, `DimensionNames`, `RowNames`, `UserData`, `VariableContinuity`, `VariableDescriptions`, `VariableNames`, and `VariableUnits`. I'm in Matlab 2018a. Upon reading the doc it seems VariableTypes is an input string to coerce a data type. – jxramos Oct 01 '18 at 20:16
-
Looks like there's also a [vartype](https://www.mathworks.com/help/matlab/ref/vartype.html) function which grabs variables from a `table` of a certain type. But that's a different operation too. I'm trying to do something more introspective than something selective. – jxramos Oct 01 '18 at 20:22
2 Answers
3
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.
-
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.` – jxramos Oct 01 '18 at 20:28
-
2@jxramos: If you want to find the class for an individual column, you can also simply say `class(t.var1)`. – Cris Luengo Oct 01 '18 at 20:59
0
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

jxramos
- 7,356
- 6
- 57
- 105
-
-
@rahlf23, sure, eg `var1: 2966185×1 double`, it's a double column vector, and var 2 and 3 are matrices of double. That appears to be what broke the `varfun` solution which probably handles single dimension variables. – jxramos Oct 01 '18 at 20:34