2
votes

When using Matlab readtable(...) (link) the function flexibly finds the best fitting field format (text, number) for each column:

tbl = readtable(filename);

one can specify to import dates as text as follows:

tbl = readtable(fileName,'DateTimeType','text');

However, since I am working with mixed data, I want to surpress that Matlab automatically sets their own format.

How can I import everything as text?

Note: I know that you can add 'Format', '%s %s ...', but I do not wish to use this option as it requires knowing the number of columns beforehand (which I do not know)

1
Have you checked detectImportOptions to get opts for readtable? It seems you can setvartype there. - Xiangrui Li

1 Answers

3
votes

You should be able to do this using detectImportOptions and setvartype as follows:

opts = detectImportOptions(fileName);
opts = setvartype(opts, 'char');
tbl = readtable(fileName, opts, 'DatetimeType', 'text');