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.

 採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日

0 投票

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 ExchangeStartup and Shutdown についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by