A"The better way..."
I hadn't noted before the symptom of repeated delimiters with dlmread; agreed that's a pit[proverbial]a[ppendage].
IMO, it's unfortunate TMW has chosen to deprecate the use of textread in favor of textscan; it has the advantage of
- returning a "regular" double array instead of only a cell array,
- doesn't need the extra fopen/fclose step again where a single file read suffices and,
- as shown below, it "counts" the record length and returns correct shape automagically whereas textscan has to be told or one has to reshape the returned array.
The above equivalent in textscan would be
'delimiter',' ', ...
textscan is the one, general function, but there are so many possibilities (as in infinite) to cover that making something that is general but also flexible is difficult; hence the specialized functions for specific cases. It does seem as though the multiple delimiters option would be a worthwhile enhancement for them; as noted, I hadn't actually noted that behavior previously as I tend to use the textread route for the above reasons. There are things it can't do that textscan can (being able to be called on the same file multiple times being a major one) but instead of deprecating it, it should be brought up to the level of textscan instead imo (or, alternatively, the option I've asked for since it was introduced, have an optional ability in textscan to return the double array directly and understand a file name as well as file handle).
Actually, on reading the source for dlmread I observed something hadn't noticed before (and I don't think it's documented; at least not well) -- if one submits an empty string for the formatting string, then textscan will do something else internally and in a regular numeric array come up with the number of fields per input record and reflect that. That is a super result that should be shouted from the rooftops by TMW but seems to be a closely held secret--
Columns 1 through 8
994.0000 270.0000 7.0000 6.0000 93.0000 5.9300 40.0000 10.0000
989.0000 312.0000 6.2000 5.2000 93.0000 5.6400 42.0000 12.0000
972.0000 455.0000 4.8000 4.0000 95.0000 5.2700 48.0000 18.0000
Columns 9 through 11
280.6000 297.1000 281.6000
280.2000 295.9000 281.2000
280.2000 294.9000 281.1000