[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #52594] textscan continues past EOL
From: |
Philip Nienhuis |
Subject: |
[Octave-bug-tracker] [bug #52594] textscan continues past EOL |
Date: |
Wed, 6 Dec 2017 05:45:49 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0 SeaMonkey/2.48 |
Update of bug #52594 (project octave):
Category: None => Octave Function
Status: None => Confirmed
Release: 4.2.1 => dev
Operating System: Microsoft Windows => Any
_______________________________________________________
Follow-up Comment #3:
In Matlab r2017b (and in r2012a albeit with different output format) the first
example gives:
>> format compact % to get rid of those pesky empty lines
>> a = textscan(sprintf('this,is\r\na,test'), '%s%s%s', 2,
'delimiter',',','EndofLine','\r\n')
a =
1×3 cell array
{2×1 cell} {2×1 cell} {1×1 cell}
>> a{1}
ans =
2×1 cell array
{'this'}
{'a' }
>> a{2}
ans =
2×1 cell array
{'is' }
{'test'}
>> a{3}
ans =
1×1 cell array
{0×0 char}
and the second example:
>> x = textscan(sprintf('1,2\r\n3,4'), '%d%d%d', 2, 'delimiter',
',','EndofLine','\r\n')
x =
1×3 cell array
{2×1 int32} {2×1 int32} {[0]}
>> x{1}
ans =
2×1 int32 column vector
1
3
>> x{2}
ans =
2×1 int32 column vector
2
4
>> x{3}
ans =
int32
0
Note that %d format specifiers give int32 and NaN doesn't exist in integer
math; to get NaNs there %f is required.
AFAICS the "endofline" value is interpreted rather as a special delimiter, it
isn't simply added to the delimiter list:
>> s = textscan ('ab:cd', '%s%s')
s =
{1x1 cell} {0x1 cell}
>> s{1}
ans =
'ab:cd'
>> s{2}
ans =
Empty cell array: 0-by-1
>> t = textscan ('ab:cd', '%s%s', 'endofline', ':')
t =
{2x1 cell} {1x1 cell}
>> t{1}
ans =
'ab'
'cd'
>> t{2}
ans =
{''}
>> t = textscan ('ab:cd:', '%s%s', 'endofline', ':')
t =
{2x1 cell} {2x1 cell}
>> t{1}
ans =
'ab'
'cd'
>> t{2}
ans =
''
''
The latter example just shows that a trailing EOL serves to make all output
columns equally sized. Otherwise columns are filled only up to the last read
value and you can get unequal column lengths in the output.
The Matlab documentation is a lot more clear these days than when I fixed
strread and textscan (the .m-file versions) several years ago.
Status -> confirmed
OS -> Any
Release -> dev
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?52594>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/