Reading an ascii file as floats
This sounds like it should be simple, but I’ve just started with Max (1 day in) and I can’t figure it out. Any hints would be appreciated!!
The file I want to import looks like this…
Two columns, 2758 rows, ascii file. I can import the file using jit.textfile, but the result is just the ascii numbers that represent each individual character. I need to end up with a 2 x 2758 matrix of floats. Do I need to explicitly parse each character and build my own float numbers?
Use the [text] object instead, and parse the file using the "line" message (use "query" to determine the number of lines). That can then go into [unpack f f] if you want to separate the two floats on each line, and then into float numberboxes to see them. Note that you may see some rounding, but I believe (?) that internally the values are the same as those from the file.
To build a jit.matrix of these floats, you’d need to use a "setcell" message for each. Should be plenty fast if you parse through the file with [uzi]. If you just need the data to grab here and there (and don’t need to see it in a matrix or do any jit.ops on it), you can just leave it in [text] and access it as needed. Transferring to [coll] is also very easy, just use the index from [uzi] to set the line number.
Should be plenty of options there to get you going ;)
Thanks for the suggestions! Since checking in to the forum last time, I found a solution to my problem by massaging the formatting of my datafile outside of max and importing directly to coll. I do appreciate you taking the time to respond!
Sounds good, sometimes it’s easier to have more usable data to begin with. Best of luck with your project and welcome to Max…careful, it’s rather addictive…!