Is it possible to convert a cell array with multiple datatypes to a dataset array in Statistics Toolbox 7.1 (R2009a) ?

I have a 10x7 cell array obtained from a database. Some columns contain strings, and some columns contain numbers. I know the number of columns, but I do not know the data type of each column.
I would like to know if I can convert it to a dataset array.

 Accepted Answer

Use the CELL2DATASET command in MATLAB 8.0 (R2012b) to achieve this.
For previous releases of MATLAB, read below for any possible workarounds:
The ability to convert a cell array to a dataset array is not available in the Statistics Toolbox 7.1 (R2009a).
As a workaround, the attached MATLAB file 'cell2ds.m' can perform this conversion. It takes as input an MxN cell array, and outputs a dataset array of similar dimensions. The second optional input argument is a cell array of strings, containing the names of the columns. If this parameter is omitted, then the function will auto-assign column names in the output dataset array as 'col1', 'col2', etc.
If "test" is the name of cell array, and if it contains 7 columns, then 'cell2ds' is called as follows:
ds = cell2ds(test) % leave out column names
Optionally, you can choose to include the column names:
ds = cell2ds(test, strings {'A','B','C','D','E','F','G'} )
The 7 strings {'A','B','C','D','E','F','G'} represent the names of each column.

More Answers (0)

Categories

Products

Release

R2009a

Community Treasure Hunt

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

Start Hunting!