Q: Low hanging fruit?

David Bateman David.Bateman at motorola.com
Tue Mar 11 09:10:51 CDT 2008


Jaroslav Hajek wrote:
> I've already started working on dlmread/dlmwrite. The thing is that
> octave-forge's
> dlmread is not quite like Matlab's - it cannot handle the range
> specification in spreadsheet format (like "A1..B10") 
I've added this behavior. See the attached version.

> and it cannot
> read the complex numbers in Matlab format
> <number>+<number>i. The Matlab version also appears to guess the separator from
> the first nonblank line, while the octave-forge version just defaults
> to tab or space.
>   
The fact that the separation character is inferred is apparently a
recent addition. I;m not sure of a reliable means to guess this, so I'd
prefer not to do it. Also Matlab's complex parsing is broken in any case
and so difficult to duplicate. For example. Consider the file

1, 2, 3
4+4i, 5, 6
7, 8, 9

matlab then returns

>> dlmread(file)
ans =

   1.0000             2.0000             3.0000         
   4.0000                  0 + 4.0000i   5.0000         
   6.0000                  0                  0         

>> dlmread(file,',')

ans =

   1.0000             2.0000             3.0000         
   4.0000                  0 + 4.0000i   5.0000         
   6.0000                  0                  0         

So it seems that matlab expects ALL fields to be in complex format. Note
that octave-forges version reads the above correctly. Try

1i+0i, 2+0i, 3+0i
4+4i, 5+0i, 6+0i
7+0i, 8+0i, 9+0i

instead. Octave-forge's version of dlmread processes this correctly.
However matlab returns

>> dlmread(file)

ans =

        0 + 1.0000i        0             2.0000         
   3.0000                  0                  0         
   4.0000 + 4.0000i   5.0000             6.0000    

Now try adding spaces to the complex numbers

1i + 0i, 2 + 0i, 3 + 0i
4 + 4i, 5 + 0i, 6 + 0i
7 + 0i, 8 + 0i, 9 + 0i

Matlab, fails to read this with

>> dlmread('crud.dat')
??? Error using ==> textscan
Mismatch between file and format string.
Trouble reading number from file (row 1, field 2) ==>  0i,

Unfortunately, my current version of dlmread current fails to read this
correctly as well. How do you want to modify way dlmread works to handle
complex numbers?

> Moreover, I'd like dlmread to start with Matrix and allocate a
> ComplexMatrix only if it
> actually encounters a complex number (real numbers are much more
> common IMHO, that's why I suppose this optimization is worth it).
>   
Ok, added that as well, together with some test code for the function.

Regards
David

-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dlmread.cc
Url: https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080311/12017f9d/attachment.ksh 


More information about the Octave-maintainers mailing list