readtable - 在Matlab中将所有列读作文本

时间:2017-08-15 15:30:58

标签: matlab

使用Matlab readtable(...)link)时,函数会灵活地找到每列的最佳拟合字段格式(文本,数字):

tbl = readtable(filename);

可以指定将日期导入为文本,如下所示:

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

然而,由于我正在使用混合数据,我想要压抑Matlab自动设置自己的格式。

如何将所有内容导入为文本?

注意:我知道您可以添加'Format', '%s %s ...',但我不想使用此选项,因为它需要预先知道列数(我不知道) < / p>

1 个答案:

答案 0 :(得分:2)

您应该可以使用detectImportOptionssetvartype执行此操作,如下所示:

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