LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a 2D Array of strings from a Text File

Please bear with me.. an absolute LabView beginner..

Basically, I have a large array of values in a text file like this

1 0 H L H L 1 1 . . . . . 1
0 1 H H H H H H . . . . . 0
.
.
.
etc..

I want to read these values into a 2D array and iterate through each row ( the columns represent digital IO of a DAQ card). I've tried various methods and failed miserably.

What is the best File IO/String/Structure controls to achieve this.

Thanks,

Wayne Mitchinson
0 Kudos
Message 1 of 8
(6,396 Views)
What is the structure of your data: only 0,1 or L,H for some logic state or ar other characters possible?
What is the delimiter char (if any) between them? Could you post a typical text file?
0 Kudos
Message 2 of 8
(6,381 Views)
One method is to save your data using the "write to spreadsheet file" vi, using whatever delimiter you choose (usually either comma ro tab char). This gives a file that can be opened with a text editor or Excel, and consists of rows of "numbers" seperated by the delimiter with an end of line char at the end of each row. When read back in using the "Read from Spreadsheet file", you can define how the values will be interpreted, either as numbers or as characters. The read data will be returned as a 2D array. This array can be indexed, either by autoindexing with loops, or by explicitly indexing to retrieve specific values (A[2,7]) and the returned values used however you wish.


P.M.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 3 of 8
(6,377 Views)
Forgive the question! My labview experience amounts to 1 day!

The data is just 1, 0 , H and L. These values just represent digital inputs/outputs (1/0 inputs, H/L outputs)
I will delimit the data with whatever works! The input file is being preprocessed using a Perl script anyway..

I'll try the "Read from Spreadsheet" function but I got the impression this only supports numerical data. I did try this, but was having trouble getting the H and L characters recognised. Probably something to do with the "format" string...

Thanks,

Wayne Mitchinson
0 Kudos
Message 4 of 8
(6,368 Views)
Read From Spreadsheet can be modified to read text. There are instructions on the block diagram on the changes required. When you make the changes, be sure to save as a different name and to a new location. Using a delimiter such as a comma in your text file, each text value will be a separate element in the output array. The other thing to try is Read Lines From File. Your output will be one long string though so if you want to separate lines and then individual values, the modified Read From Spreadsheet is the best function to use.
0 Kudos
Message 5 of 8
(6,364 Views)
I'll give this a go.

So I need to work out how to convert the output arrays from the original "Read From Spreadsheet" VI to string arrays. Using the %s format with this modified "Read from Spreadsheet" should give me the desired result.

I feel I'm a step closer. Thanks!

Wayne Mitchinson
0 Kudos
Message 6 of 8
(6,354 Views)
Instead of Read from spreadsheeet.vi I would use Read characters from file.VI together with the spreadsheet string to array function (if you look into Read from spreadsheet file.vi, you'll find a similar approach there). This gives you more flexibilty.

See the attached example:
Message 7 of 8
(6,348 Views)
Thanks Fahlers

I successfully modified the "Read From Spreadsheet" VI and got my 2D Array of strings from a text file, but I will look at your example. Its seems there are many ways to peel an orange using Labview 🙂

Cheers,

Wayne Mitchinson
0 Kudos
Message 8 of 8
(6,345 Views)