LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to scan an array from a text file

Hello,
 
I was wondering ... what is the best way to scan a 2d array of numbers from a text file.
An example of such a text file:
 
  0.0000000e+000  3.5000000e+001  3.5100000e+001  3.5200000e+001  3.5300000e+001  3.5400000e+001
  3.4000000e+002 -5.4998976e+000 -1.4999700e+000  0.0000000e+000 -1.4999700e+000  2.9999400e+000
  3.4066602e+002 -5.5554708e-002 -5.5554708e-002  1.1110942e-001 -4.4444529e-001  1.6666667e-001
  3.4133203e+002 -1.2499914e+000  2.2499949e+000  7.5000244e-001 -2.2499826e+000  1.7500051e+000
  3.4199805e+002  6.8420986e-001  1.2105260e+000  1.1578951e+000  1.1578951e+000  1.2631568e+000
  3.4266406e+002  7.1428082e-001  1.5714212e+000  1.9999914e+000  5.7142626e-001  5.7141972e-001
  3.4333008e+002  2.6667133e+000  3.3333832e+000 -1.1753165e-005 -3.3334667e-001 -1.1753165e-005
See also attached file...
 
I tried the "Read from spreadsheet file" but was not successfull.
Thanks for the help!
John
0 Kudos
Message 1 of 9
(3,633 Views)

Hi John,

use the "read from text file.vi" and then the "spreadsheet string to array function". Before that replace all "\s\s" to "\s" code display. After that you will have your 2d array of double values.

Mike

0 Kudos
Message 2 of 9
(3,630 Views)

Hi John,

here a picture which shows what i mean.

Mike



Message Edited by MikeS81 on 05-07-2008 03:44 PM
0 Kudos
Message 3 of 9
(3,624 Views)

Read From Spreadsheet will work as long as you specify the correct delimitor.



Message Edited by Dennis Knutson on 05-07-2008 07:52 AM
Message 4 of 9
(3,616 Views)
Mike,

I did not know you could feed an array of delimiters to the Spreadsheet String to Array function. I could have used that yesterday. Thanks for showing that.

Lynn
0 Kudos
Message 5 of 9
(3,611 Views)
Thanks all for the help. This works great!
0 Kudos
Message 6 of 9
(3,598 Views)
can anyone shed some light as to what a \s delimitor is used for?

<edit> ok I figured it out, its a space constant Smiley Happy


Message Edited by nrp on 05-07-2008 03:16 PM
0 Kudos
Message 7 of 9
(3,596 Views)
I don't understand your question. What's wrong with using a space for a delimiter? In some cases, like the above, it's perfectly acceptable.
0 Kudos
Message 8 of 9
(3,593 Views)
I think you may have misinterpreted my (poorly worded) question.

Essentially, I had not come across a \s delimitor before, and didnt know what it was. My first attempt at googling it proved fruitless, and thus my question was borne.

After a bit more thought and a quick check at the default constants in the string pallete I figured it must be a space constant.

My personal preference is still to use a tab constant though, and its one byte less (per record) than putting two spaces in Smiley Happy
0 Kudos
Message 9 of 9
(3,581 Views)