Reading in data with spaces
Afficher commentaires plus anciens
I have a bunch of data with spaces in it that is fixed width. It is formatted such that each "column" is a fixed number of characters wide (including space characters). I've been trying to use "textscan" with a format like this: '%6c %6c %6c %6c %6c' but it seems to A)ignore spaces a the beginning of the string (this serves to throw off the 'count' when the first number goes from 9 to 10 for example) and B)not recognize blanks in the middle or at the ends. eg: "___8.5|___9.2|______|______|___7.6" where "_" represents one space and "|" are added for clarity. I need this to read in with 8.5 in the first cell, 9.2 in the second, and 7.6 in the 5th cell. I can tolerate it being a string (and converting later) as long as the column placement is preserved.
1 commentaire
You've stumbled into the black hole of C (and hence Matlab) fixed-width, non-delmited input; there's no way to so with a missing field other than by reading as a character array and parsing the lines using counted string indexing--no input scanning format will honor the blanks.
See the preceding discussion on the subject for more than you really want to know of the issues that can arise...
As noted many times before, I've begged for TMW to provide a solution for 20+ yr to no avail.
Oh, I see you also did a search and came across the old (ca. 2009) TMW post apologizing for the limitation and demonstrating the fixed-width parsing.
I'd urge to submit an enhancement request and add another "voice in the wilderness" to try to get something done (but wouldn't hold my breath waiting... :( )
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!