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

7 次查看(过去 30 天)
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.

采纳的回答

MathWorks Support Team
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by