Error using readtable. File extension txt not recognized
32 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Christian von Spreckelsen
am 5 Dez. 2016
Kommentiert: Christian von Spreckelsen
am 9 Dez. 2016
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 Kommentare
Walter Roberson
am 5 Dez. 2016
Sorry, nfts should have been NTFS, the main Windows File System. But it sounds like that is not the issue.
Antworten (2)
Walter Roberson
am 5 Dez. 2016
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 Kommentare
Guillaume
am 9 Dez. 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
am 9 Dez. 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?
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!