Mixed Data Types In a Table

8 views (last 30 days)
Greg
Greg on 9 Dec 2014
Answered: Sean de Wolski on 9 Dec 2014
I'll preface this by stating I'm new to Matlab.
I have data stored in a table, and that table contains numeric (double), categorical, and ordinal data. I need to convert the table to a matrix of type "double" to run predictive classification (fitensemble). If I try the command: double(X), I get an error that "Conversion to double from table is not possible". I can't convert the table to an array, because its not possible to concatenate double and categorical arrays.
I've tried:
classreg.regr.modelutils.predictormatrix (X);
which works, but drops the last column of the table.
How can I (efficiently) create a matrix of predictors from a table of mixed data types?
Thanks.

Accepted Answer

Sean de Wolski
Sean de Wolski on 9 Dec 2014
% Simulate data
T = table(rand(10,1),categorical(cellstr(('rgbbrgrrbr').')))
% Convert to double and extract with {}
Td = varfun(@double,T)
mat = Td{:,:}

More Answers (0)

Community Treasure Hunt

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

Start Hunting!