Hello, I am trying to import data from Excel (.xls). This data has a single column of mixed (numeric and string) data that is | (bar) delimited. My goal is to import this data and seperate each delimited portion into a seperate columns while maintaining the rows. Essentially, I am trying to do the Excel "Text to columns" with MATLAB. Thank you
Hi Fangjun what Matlab version are you using? Unfortunately I cannot access the archived documentation to check the documentation for older Matlab releases and the functionality of importdata as my license does not allow for that. See http://www.mathworks.com/help/doc-archives.html and check for your version. I would be interested to hear if something changed and broke backward/forward compatibility of this function.
I tested on R2010b and the results are same as yours. I have no idea. Maybe importdata() is not smart enough to handle inconsistent data format (the 4th line is certainly different than the first 3 lnies).
You need to provide a sample of data that is representative of your real data. In your comments on your question, you have consecutive delimiters and no numeric data. In your example above, you have lines that have different numbers of delimiters. What is your real data look like? What is your expected output?
This was the problem that I was running into. There are about 10 MATLAB functions that are temptingly close to "Text to columns", but I have not found a way to do it.
Well, if your original file is in .txt file in my example, you can use
[y1,y2]=textread('test.txt','%s%d','delimiter','|') to get it. If your original file is in .xls file, then you have to use xlsread() or importdata() to get the data in a format like x above and then do porcessing.
What is your text file look like? Can you post an example? I ran the command and it didn't have any problem. Also, type help textread to look at the calling syntax of textread.
That must be that we are using different version of Matlab. I am using R2007b. You must use a new version. It looks like importdata('test.txt','|') could work as Bob Hamans suggested. Type x.data and x.textdata to see if that meets your need.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9452-importing-delimited-data-from-excel-xls-and-text-to-columns#comment_20685
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9452-importing-delimited-data-from-excel-xls-and-text-to-columns#comment_20685
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9452-importing-delimited-data-from-excel-xls-and-text-to-columns#comment_20704
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/9452-importing-delimited-data-from-excel-xls-and-text-to-columns#comment_20704
Sign in to comment.