Mon 28 Mar 2016 07:09:44 PM UTC, comment #5:
@Mike:
Which docs do you refer to?
If it's the Matlab docs, yes they are confusing. I think that adequately reflects the "one tool for all you can think of" that textscan came to be.
As to those docs, I'm even unsure if it is "\b\t" or " \b\t" (note the space) that should be the default whitespace.
Anyway this bug report uncovers a can of worms in a way.
My understanding (as far as I could infer textscan's working) is as follows:
- whitespace (" \b\t") serves as a type of delimiter of which several consecutive ones are always collapsed into one;
- delimiter (default a space) also delimits text fields. Consecutive ones will not be collapsed into one ... unless multipledelimsasone is specified;
- endofline (\r\n, r\r, or \n) are default delimiters and added to the delimiter collection, unless it is set to empty in which case it is treated as whitespace.
So whitespace, delimiters and endofline overlap in some sense.
Things become interesting if whitespace, delimiters and endofline all occur in a file / text srring and in textscan's input arguments.
Although I largely rewrote the textscan.m/strread.m combo, my memory gets a bit confused, sorry. ATM I am morphing strread.m from a self-contained function into one invoking binary textscan as backend and I'm bitten by exactly these "uncertainties" - IOW in hindsight I sometimes doubt if I've been doing the right things all along.
Back to whitespace, Matlab 2016a prerelease does this:
... showing that whitespace somehow gets "promoted" to delimiters, regardless of numeric or text fields in the input. Only \r (char(13) is treated as special. But maybe that could be due to the default "endofline" character (intractably for us inferred from the input file/string).
It could be that ML's textscan doesn't explicitly turn whitespace into delimiters, but simply stops reading whenever a next character doesn't fit in the numerical scheme, or when reading text, assumes whitespace doesn't occur in text fields.
The rationale may be very logical and straightforward, but the results can be a bit confusing - for me at least :-)
As to the example in comment #3:
Rik's first command gives:
...IOW the same as in comment #3.
|