06-10-2021 07:22 AM
I have a .txt file that is formatted as follows:
I wanted to read each column of the file as an array (so I can then manipulate the data in the 3rd row), but so far what I've managed to do is to get LabVIEW to read each row of the .txt file (skipping the first couple of rows) and returning an array where each element is a row from the .txt file.
I know LabVIEW has a function to find numbers in a string but it stops after finding the first number, which, given my current code, means I can only turn the integers (1-15) into an array.
Is there another way of doing this?
.
06-10-2021 07:39 AM - edited 06-10-2021 07:41 AM
Hi logolepser,
@logolepser wrote:
Is there another way of doing this?.
Switch ReadSpreadsheetFile to the "DBL" instance (instead of "String"). This will give you a 2D array of DBL values.
Now use IndexArray to index those columns as needed!
(Another idea: to autoindex columns instead of rows you just need to transpose a 2D array…)
Btw. we cannot debug/edit images using LabVIEW. Usually it makes sense to attach real VIs (and txt files) instead of images of VIs/txt files…
06-10-2021 08:31 AM
Sometimes it is easier to read a line at a time (as a string) and "feed" the line to "Scan from String" to turn it into an Array of <Some Type> (in your case, I'm guessing you want "Dbl").
In your example, the first (header) line is different in format, so you'll read this separately. I'm assuming the remaining lines are supposed to be 3 numeric values, two integers and one Float (with a "European comma" instead of a "British/US period", two terms I just made up). Fortunately, you have a space between them, so the format string "%f %f %f" will parse this for you. You now have a 1D Array of Dbl. Put this in a While/For loop where you read a line, Scan from String, output 1D Array that becomes a 2D Array (as you want) when brought out of the While Loop.
Note -- when you drop the Scan from String function on your Block Diagram, the output, by default, is Dbl. Simply drag that output terminal down twice (to make 3 Dbl outputs) and the function will create the appropriate Format String for you, which you can view by write-clicking the function and choosing "Edit Scan String".
Bob Schor