help-octave
[Top][All Lists]
Advanced

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

problems with latest strread (comma delimiters)


From: krthie
Subject: problems with latest strread (comma delimiters)
Date: Mon, 17 Oct 2011 17:04:10 -0700 (PDT)

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.



> octave>  [a1,a2]=newstrread("1,2\n3,4\n", '%f%f', 'delimiter',',')
> a1 =
>    1
>    4
> a2 =
>     23
>    NaN
> 
Somehow, the newline was not considered as a "new record" and just ignored.
Instead, the 3.2.4 version of strread reads this correctly:


> octave>  [a1,a2]=strread("1,2\n3,4\n", '%f%f', 'delimiter',',')
> a1 =
>    1
>    3
> a2 =
>    2
>    4
> 
Remarkably, writing the string to file and then reading it with (both 3.2.4
and new) textread works just fine.


> octave>  f=fopen("test.csv","w");fprintf(f,"1,2\n3,4\n");fclose(f);
> octave>  [a1,a2]=newtextread("test.csv",
> '%f%f','delimiter',',');assert(a1==[1;3]);assert(a2==[2;4])
> 

Here's another case where both the 3.2.4 and new strread (and textread)
ignore some unknown characters, which causes rather strange results:


> octave>  [a1,a2]=newstrread("1a2\n3,4", '%f%f')
> a1 = NaN
> a2 =  34
> 
Arguably returning a NaN for the first line is ok, but ignoring the comma is
just wrong.

Thanks

Kris

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


reply via email to

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