Readtable produces a 1x 1 table full of strange characters
4 views (last 30 days)
Show older comments
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 Comment
Les Beckham
on 17 Oct 2023
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.
Answers (1)
Sulaymon Eshkabilov
on 17 Oct 2023
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 Comments
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!