help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems with latest strread (comma delimiters)


From: PhilipNienhuis
Subject: Re: problems with latest strread (comma delimiters)
Date: Tue, 18 Oct 2011 08:40:56 -0700 (PDT)

krthie wrote:
> 
> Hi
> 
> I'm trying to use textread but had trouble on Octave 3.4.2 (built from
> source on Ubuntu 11.04). Therefore, I downloaded the latest strread.m and
> textread.m from mercurial, renaming them to newstrread.m and
> newtextread.m. (IMPORTANT: I didn't update anything else. That might be my
> mistake). 
> 
> Indeed, the latest textread fixed my trouble (Thanks!), but I see weird
> behaviour for strread.
> 
> < quote >
> octave>  [a1,a2]=newstrread("1,2\n3,4\n", '%f%f', 'delimiter',',')
> a1 =
>    1
>    4
> a2 =
>     23
>    NaN
> < /quote >
> 

If you do not specify a delimiter character in strread calls, any whitespace
character is supposed to be delimiter character. (Default whitespace = " ",
"\n", "\t", "\r" & "b".)
However, if you do specify a delimiter, only that delimiter char is actually
used and whitespace is simply ignored.

In your case, 
[a1, a2] = strread ("1,2\n3,4\n", '%f%f', 'delimiter', ",\n")
works as desired.

That it does work "OK" with textread and textscan is because these have a
somewhat obscure option "endofline" (see help of those functions) whose
default is to automagically include EOLs in the delimiter collection.

Admittedly this doesn't look quite obvious. But AFAIK this *IS* the intended
behaviour. 
Be aware that reading from a string (supposedly a long, relatively
unstructured sequence of characters) is supposed to be different than
reading from a text file (which is supposed to be structured into "lines").
Hence the reason that textread has an "endofline" parameter.

FYI, as strread currently does the "low-level" work for textread,.you could
also call strread like this:
[a1, a2] = strread ("1,2\n3,4\n", '%f%f', 'delimiter', ",", "endofline",
"\n")    # Note: undocumented

BTW, the default whitespace char collections for strread, textread and
textscan in ML are all different. Octave mimics this as far as reasonably
possible.

Philip

< rest snipped> 

--
View this message in context: 
http://octave.1599824.n4.nabble.com/problems-with-latest-strread-comma-delimiters-tp3913839p3915796.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]