Readtable produces a 1x 1 table full of strange characters
1 次查看(过去 30 天)
显示 更早的评论
I am loading tables from several large nonuniform .txt files delaminated with spaces. I'm using readtable and most of the tables get loaded without an issue but some files generate a 1x1 table full of stange characters. The code I'm using to load:
filename = 'filename.txt'
opts = detectImportOptions(filename);
opts = setvartype(opts,'char'); % or 'string'
Table = readtable(filename,opts);
I can't tell what is causing some files to be read like this.
1 个评论
Les Beckham
2023-10-17
If you provide a sample file that causes this issue you will be more likely to get a good answer. Use the paper clip icon in the INSERT section of the comment editor toolbar to attach it.
回答(1 个)
Sulaymon Eshkabilov
2023-10-17
If some of the imported data looks strange, that means the setvartype option is not appropriate for the data to be imported. See these two examples:
filename = 'DATA_2_MIX.txt';
opts = detectImportOptions(filename);
opts = setvartype(opts,'double'); % 'single','char' or 'string'
Table = readtable(filename,opts)
filename = 'DATA_2_MIX.txt';
opts = detectImportOptions(filename);
opts = setvartype(opts,'char'); % 'single','char' or 'string'
Table = readtable(filename,opts)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!