Why is xlsread not working with text file? Documentation says it should work with other any file that Excel can open.
Show older comments
Documentation for the xlsread command says:
" On Windows® systems with Microsoft Excel software, xlsread reads any file format recognized by your version of Excel. "
So that sounds to me like xlsread should be able to open some .txt files that I exported from AFM software. The text file consists of a column header and a column of numbers written in scientific notation. I can open said text files directly in Excel if I use the Open with -> command in the right-click context menu in Windows. Excel interprets the contents cleanly, placing the header text at the top of the column and each subsequent number into a cell.
However, when I try to use xlsread to read the text file, I get the error: File my file.txt not in Microsoft Excel Format. (I substituted "my file" for the actual name.)
Accepted Answer
More Answers (1)
Image Analyst
on 31 Jul 2014
0 votes
Try something else, like importdata() or textscan() or readtable().
16 Comments
Alexei
on 31 Jul 2014
Image Analyst
on 31 Jul 2014
Why don't you attach your text file so we can see what's wrong with it?
Alexei
on 31 Jul 2014
Star Strider
on 31 Jul 2014
Edited: Star Strider
on 31 Jul 2014
FWIW, Excel 2010 (Win 8) won’t open it as an Excel file (it brings up Excel’s Text Import Wizard). Save it with an .xls extension and see if that works.
I got importdata to open it, only to find its contents to be:
'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'
'<html><head>'
'<title>400 Bad Request</title>'
'</head><body>'
'<h1>Bad Request</h1>'
'<p>Your browser sent a request that this server could not understand.<br />'
'</p>'
'</body></html>'
Image Analyst
on 31 Jul 2014
Edited: Image Analyst
on 31 Jul 2014
I can't even see it. Firefox says:
Bad Request
Your browser sent a request that this server could not understand.
Probably because from what Star said, it's actually an XML or HTML file and it's trying to display it as a web page.
Image Analyst
on 31 Jul 2014
I don't think you attached the correct file.
Star Strider
on 31 Jul 2014
I have no idea what it means, other than that the file you attached it not the file you likely wanted to attach.
Choose a different file.
Alexei
on 31 Jul 2014
Alexei
on 31 Jul 2014
Image Analyst
on 31 Jul 2014
Paste it into the editor window then. See if that works.
Star Strider
on 31 Jul 2014
Edited: Star Strider
on 31 Jul 2014
I doubt it’s the TMW site. How did you try to upload your file?
----------
EDIT — I just uploaded an old Excel file that I got from somewhere, closed this comment, clicked on the file link to open the file, and it worked fine. It’s not the site here. (I’ll take the file down in a few minutes, since there’s no other reason for it to be here, other than for testing purposes.)
Image Analyst
on 1 Aug 2014
Edited: Image Analyst
on 1 Aug 2014
I could read it just fine with Excel 2010 and MATLAB R2014a. I suspect you have an old version of Excel, like 2003 or something, where the number of rows was limited to 16384. Your text file has slightly over that and perhaps that's causing the problem. Can you cut the number of lines down to 100 or 1000 or so and test it? Here's my code:
[num, txt, raw] = xlsread('text.csv');
and attached is the file it successfully ran with (copied and pasted from your web site). num, txt, and raw all have exactly what you'd expect to be in them.
Star Strider
on 1 Aug 2014
To rename them in a script, movefile is likely your best friend. See Examples —> Renaming a File in the Current Folder.
Categories
Find more on Large Files and Big Data 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!