Why does %c not read whitespaces with the TEXTREAD function?

Why does %c not read whitespaces with the TEXTREAD function?
I am trying to read a file using TEXTREAD. Here is an example input file:
one two three four
one two three four
I should be able to read this file using
[a, b] = textread('file', '%3c%3c%*[^\n]');
and expect the output to be:
a=[ 'one'; 'one' ] and
b=[ ' tw'; ' tw'; ]
But I get
a=[ 'one'; 'one' ] and
b=[ 'two'; 'two' ]
It appears that the whitespace between the 'one' and 'two' is skipped.

 采纳的回答

This bug has been fixed for Release 14 (R14). For previous releases, please read below for any possible workarounds:
This is a bug in MATLAB that has been brought to the attention of our development staff so that it may be fixed in a future release of MATLAB.
As a workaround, you need to explicitly define the space as a whitespace character. You can do this by passing the 'whitespace' argument to the TEXTREAD command.
For example, your command line may look something like the following:
[a, b] = textread('file.m', '%3c%3c%*[^\n]','whitespace','');

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by