Why do I receive unexpected results when I use "space" as a delimiter in the DLMREAD function in MATLAB 7.0 (R14)?

7 views (last 30 days)
In MATLAB 7.0 (R14), using a "space" as a delimiter (e.g. ' ') in conjunction with DLMREAD or TEXTREAD will result in two adjoint spaces introducing an empty ( [] ) number in the matrix result.
For example, if the input file is a single line "1 2", where there are two spaces between the 1 and the 2, then the vector created by DLMREAD will have three elements: 1, [], and 2.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This behavior is a result of a change made to DLMREAD. The help for this function explains:
When a delimiter is inferred from the formatting of the file, consecutive whitespaces are treated as a single delimiter. By contrast, if a delimiter is specified by the DELIMITER input, any repeated delimiter character is treated as a separate delimiter.
As a result, you must let MATLAB infer the delimiter in order for consecutive occurrences to be treated as a single occurrence. If you wish to specify a row and column to read from but also want MATLAB to infer the delimiter, try using a blank string as a delimiter:
q=dlmread('mytxt.txt','',1,1)

More Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!