Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: textread/textscan not reading formatted text with whitespace
Replies: 19   Last Post: Oct 22, 2013 5:13 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Norbert Marwan

Posts: 7
Registered: 10/2/13
Re: textread/textscan not reading formatted text with whitespace
Posted: Oct 22, 2013 3:58 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

So, after some mail exchange with the Matlab support I got a solution. In my opinion, it is not very convenient but finally it works:

fid = fopen('test.txt');
tmp1 =textscan(fid,'%s','delimiter','');
fclose(fid);
tmp = tmp1{:};
% this can read input fields with predefined width! it adds commas between these fields
tmp = cellfun(@(x)regexprep(x,'(....)(..)(..)(...)(...)','$1,$2,$3,$4,$5'),tmp,'UniformOutput',false);
a = cellfun(@(x)textscan(x,'%4.0f%2.0f%2.0f%3.0f%3.0f','delimiter',','),tmp,'UniformOutput',false);
a = cellfun(@(x)cell2mat(x),a,'UniformOutput',false);
a = cell2mat(a);

The interesting point here is '(....)(..)(..)(...)(...)' which allows considering the fixed field width. I wonder why such is not working in textread or textscan directly ?

I mentioned that textread and textscan is confusing because it pretends such functionality but cannot do it. The ability to use formatted strings in textread or textscan is completely useless because it nevertheless needs field separators. But then working with field separators is mostly sufficient.

The support again insisted to not change these functions. I do not why. It seems that Mathworks is afraid to realise suggestions from its customers ?


Date Subject Author
10/2/13
Read textread/textscan not reading formatted text with whitespace
Norbert Marwan
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
Norbert Marwan
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
Derek Goring
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/3/13
Read Re: textread/textscan not reading formatted text with whitespace
Norbert Marwan
10/3/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
Norbert Marwan
10/2/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/3/13
Read Re: textread/textscan not reading formatted text with whitespace
Norbert Marwan
10/3/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/22/13
Read Re: textread/textscan not reading formatted text with whitespace
Norbert Marwan
10/22/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/22/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/22/13
Read Re: textread/textscan not reading formatted text with whitespace
Norbert Marwan
10/22/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb
10/22/13
Read Re: textread/textscan not reading formatted text with whitespace
dpb

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.