readtable reading string columns as matrix when lots of empty rows.

13 次查看(过去 30 天)
I work with very large tables (3 million or so rows). I use the readtable function to import them into matlab. recently I noticed a bug, when I have a large amount of empty cells in a column that is supposed to be a column of strings. readtable reads the column as a matrix and all the cells are NaN. Is there a way to set specific columns to be read as cells or chars to prevent this problem. I would prefer to not format all the columns as matlab is pretty good at this already and they can move around and change.
The code works fine with smaller data or if the strings show up earlier in the data.
Any help would be appriciated.

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-6-29
编辑:Scott MacKenzie 2021-6-29
You ask: Is there a way to set specific columns to be read as cells? Yes, you can do this:
opts = detectImportOptions('filenname.xlsx');
opts = setvartype(opts, {'name_of_column'}, 'cell');
T = readtable('filename.xlsx', opts);
See the readtable documentation for a detailed example.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by