Reading an ascii file as floats

    Jun 17 2013 | 6:42 pm
    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...
    0 -0.07 0.087861806 -0.017723613 0.175723613 -0.387255298 0.263585419 -0.478504518 0.351447225 -0.089813656 ...
    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?

    • Jun 17 2013 | 9:27 pm
      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 ;)
    • Jun 17 2013 | 10:37 pm
      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!
    • Jun 17 2013 | 10:50 pm
      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...!