Modify then write data in the given format
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
Accepted Answer
0 votes
- Read the first three columns to one string, since they shall only be copied to the output file.
- Read the following six columns to a double array.
- Add 1 to the prescribed elements of the array
- Use the same format string to write the data (don't forget new-line)
27 Comments
- It's possible to read your example with textscan and a similar format specifier - see my addendum. Or are we speaking past each other?
- Can we be sure that "undocumented" behavior of textscan doesn't change between releases?
- "Somewhere some months ago"   might be this thread read ascii non-delimited file.
- "older Fortran and are still around"   that's true and most large "csv-files" contains fixed-width columns. Long time ago reading fixed-format text-files was much faster than reading free-format. Is that still the case?
- Rows with leading spaces causes problems. '%s' handles it, but '%f' doesn't.
- Regarding the documentation in general I think that it's okay and is being improved over time. However, I've have wishes. More elaborated problem oriented examples, e.g. "How to read fixed width text file" and "How to read multi-section text files". Easier to find a function when I forgotten the name. And more.
- textscan   Knowledge on C might helps to understand why, but must not be required. (If needed that should be clearly stated.) Regarding 'Delimiter','' and 'Whitespace','' I still think they don't cause the promised behavior. Recently, I read some documentation on Fortran format specifiers. We only want a small subset.
- The documentation of the low-level HDF5-functions is another example of referring to third party documentation. In this case I think it is okay.
- The documentation on Regular expressions is okay I think. However, I think more elaborated examples would be useful.
- the first one (with commas) is the best (i.e. most readable) and
- that something like this would fit better in the Matlab environment than a syntax, which mimics fortrans FORMAT
- Sure, it's just "syntactic sugar".
- Maybe, a syntax like this would be enough (with a fortran engine)
- I don't understand TMW
- reading with textscan together with a format-string based entirely on %wc where w is a whole number
- format-string according to my comment above
- converting to numerical in a second step - maybe with str2num.
- do some timing experiments
- Is there a need for a new function to read fixed-formatted text files?
- Does my prototype handle the most frequent types of fixed-width files?
- A good fortran-mex-function, how much faster would that be?
- On input, the F data edit descriptor transfers w characters from an external field and assigns their real value to the corresponding I/O list item. The external field data must be an integer or real constant.
- If the input field contains only an exponent letter or decimal point, it is treated as a zero value.
- If the input field does not contain a decimal point or an exponent, it is treated as a real number of w digits, with d digits to the right of the decimal point. (Leading zeros are added, if necessary.)
- If the input field contains a decimal point, the location of that decimal point overrides the location specified by the F descriptor.
- If the field contains an exponent, that exponent is used to establish the magnitude of the value before it is assigned to the list element.
- An explicit 1X to skip the delimiter, or
- A compiler-dependent extension that recognizes the comma as a delimiter(*)
- Nobody would read them, and
- It would take a "language lawyer" to parse the result in the exotic cases if did.
More Answers (0)
Categories
Find more on Sudoku 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)