Importing line-by-line from a text file
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
0 votes
Share a link to this question
1 Comment
Share a link to this comment
Accepted Answer
0 votes
- " how to tackle the spaces"   depends on how you want the spaces in the resulting string variable values
- "line-by-line"   what exactly do you mean?
- use Import Data interactively to read from a file of format B (one header line, comma separated, varying width) to a table. Make sure to uncheck Multiple Delimiters as One and select table. I've tested; it worked fine.
- spend time with the documentation of table instead of fighting file formats.
7 Comments
Share a link to this comment
- the entire file fits easily in memory
- each row is approx. 480 bytes
- the file has 120 columns
- It's not practical to write a format-specifier "manually"
- "text file had fixed with" are you sure? Inspection in editor show me that all columns don't have fixed width. I doubt that it is safe to rely on position.
- there are 134 names in the header line, but only 123 columns in the first two data rows. Why?
- all rows do not contain the same number of columns

Share a link to this comment
Share a link to this comment
- I found out a text file with fixed width's this time, I think its gonna be easy. But I have a doubt how do I compare a fixed width for example a state code is 356 and is placed at the start of each line. So for an if statement should I use eg: if(NBIdata(1:3)=='356')
- Also how do I write to direct the pointer from one line to another?





Share a link to this comment
More Answers (0)
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)