help-octave
[Top][All Lists]
Advanced

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

TEXTREAD is broken (again) ?


From: Tribo Laboy
Subject: TEXTREAD is broken (again) ?
Date: Thu, 22 Apr 2010 17:00:47 +0200

Hello!

I am trying to import some mixed data into Octave. I am using Octave
3.2.4 MinGW32 from SF.net.

The data is in a file called: "testfile.csv", which has this format:

1,pretest,1,10.0051348436
2,posttest,2,10.0051348436
3,posttest_plus16h,3,10.0051348436
4,pretest,1,20.0102696873
5,posttest,2,20.0102696873
6,posttest_plus16h,3,20.0102696873
7,pretest,1,50.0256742182
8,posttest,2,50.0256742182
9,posttest_plus16h,3,50.0256742182

I use TEXTSCAN and it spits out an error like this:
>>> [a,b,c,d] = textread("testfile.csv","%f,%s,%f,%f")
>>>error: value on right hand side of assignment is undefined

I search on the web and I find that in Mercurial there is a new
function TEXTREAD and it comes with a companion function STRREAD.
Here:
http://hg.savannah.gnu.org/hgweb/octave/rev/31a22d48f41f
How nice!

After downloading and renaming the file to TEXTIMPORT (and all the
occurrences of 'TEXTREAD' within it), now I try the same thing:

>>> [a,b,c,d] = textimport('testfile.csv','%f,%s,%f,%f')
a =

   NaN
   NaN
   NaN

b =

{
  [1,1] = 2,posttest,2,10.0051348436
  [2,1] = 6,posttest_plus16h,3,20.0102696873
  [3,1] =
}

c =

   NaN
   NaN
     0

d =

   NaN
   NaN
     0

>>>

The result is clearly not what I have expected. Trying to use STRREAD
directly results in this:

>>> [a,b,c,d] = strread('1,pretest,1,10.0051348436','%f,%s,%f,%f')
a = NaN
b =

{
  [1,1] =
}

c = 0
d = 0
>>>

Also very far from what is expected.


Finally, I have downloaded a piece called READTEXT from MatlabCentral
and hacked it to work under Octave. It basically reads mixed data into
a cell array and then its is very easy to convert it to cellstrings
and numeric matrices.

So here are the questions:

1. What am I doing wrong with the TEXTREAD function, its newer version
and with STRREAD? BTW STRREAD cannot reproduce the mixed data examples
given on the Mathworks documentation website for their version of
STRREAD.

2. Isn't it about time to get a decent function for reading mixed data
into Octave?

Regarding the second point I am ready to contribute the hack on
READTEXT that I did, but there are several points to consider:
a) I am not sure about the licensing compatibility. READTEXT is BSD.
b) I am a Matlab, not Octave programmer, so the help part and the
built-in tests of an octave M-file are a complete mystery to me.
Hence, my files will not be directly suitable for inclusion in Octave
or Octave-forge.

Regards.


reply via email to

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