lua-users home
lua-l archive

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


Hey gang,

I'm trying to take tabular data from an ascii file and convert it into a MATLAB *.mat file. The one thing that I'm really struggling with is forcing the binary write mode to fit in the bytes. Say for instance I have the following data:

#Time  Pos.x  Signal
0.1    1000   1.24e-10
0.2    1010   3.714e-11
0.3    1020   5.535e-11

Assume that the above data is stored in a lua table, like so

data = {}
data.raw = {}
data.label = {}
table.insert(data.label,'Time')
...
data.raw['Time'] = {}
table.insert(data.raw['Time'], '0.1')
....

In my script, I've used the following:

f=assert(io.open('out.mat','wb')

f:write(...)


where ... is the appropriate data. Say that I've stored 5.535e-11 via write like this:
f:write(5.535e-11)

If I examine my out.mat in vim and converted it into hex, I see that it consumes a byte for each character (i.e., I see 5.535e-11). How do I force the write to put the data in 8-byte double precision format? Has anyone done anything like this before? Hopefully my question makes sense.

Thanks for any advice,
Keith
--
Keith Pimmel     ~~~~     Dynetics, Inc.     ~~~~     256.964.4717