Error using readtable. File extension txt not recognized
Mostrar comentarios más antiguos
Hi
I made a script for loading a .txt file and doing some calculations on the loaded data. It works fine for me and several other i shared the script with, but with a couple of people it doesn't work. When they run the script and choose the file to load, they get following message

He is trying to load the excact same file that works for everyone else. The file is attached to this post. Anyone who had a similiar problem or knows how to fix this?
EDIT: He has no problem loading the files when using the "Import Data" button from the toolbar, only when it is through readtable in a script he got the problem. Besides that we just found out he has got the 2015b version, where mine is 2016b. But it seems unlikely that readtable didn't know how to load a .txt file before 2016
5 comentarios
dpb
el 5 de Dic. de 2016
Don't have recent version to be able to test but I'd venture the doubled-up '.TXT' is confusing the parser. Fix the file name to only include one extension instead of two and bet it'll work.
Christian von Spreckelsen
el 5 de Dic. de 2016
Walter Roberson
el 5 de Dic. de 2016
Try renaming to .txt extension. If that works check to see if the person is using a nfts that has been configured for case sensitivity, which is uncommon but permitted.
Christian von Spreckelsen
el 5 de Dic. de 2016
Walter Roberson
el 5 de Dic. de 2016
Sorry, nfts should have been NTFS, the main Windows File System. But it sounds like that is not the issue.
Respuestas (2)
Walter Roberson
el 5 de Dic. de 2016
0 votos
Try adding 'filetype', 'text' to the readtable() call. I am looking at the R2015b documentation and it certainly should support .txt extension, but give it the hint.
Question: the systems that do not work, do they have Excel installed or not? If they do not then notice 'basic'
Indicator for reading in basic mode, specified as the comma-separated pair consisting of 'Basic' and either true, false, 1, or 0.
basic mode is the default for systems without Excel for Windows. In basic mode, readtable:
- Reads XLS, XLSX, XLSM, XLTX, and XLTM files only.
2 comentarios
Christian von Spreckelsen
el 9 de Dic. de 2016
Guillaume
el 9 de Dic. de 2016
'Filetype', 'text' should indeed fix the problem.
For text files, the presence or lack of excel does not matter and 'Basic' has no effect as readtable uses textscan to parse the file in any case.
Guillaume
el 9 de Dic. de 2016
You can look at the code that readtable uses to detect the filetype (in matlabroot\toolbox\matlab\datatypes\@table\readFromFile.m), it's not complicated.
You'll get an error if
[~, ~, fx] = fileparts(filename);
ismember(lower(fx), {'.txt' '.dat' '.csv'})
returns false. So what does lower(fx) return on those system where it does not work?
1 comentario
Christian von Spreckelsen
el 9 de Dic. de 2016
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!