Readtable produces a 1x 1 table full of strange characters
4 ビュー (過去 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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!