LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from text file and convert to numeric 1d array

Solved!
Go to solution

I looked around a lot of documentation and found out either some of them outdated or simply lack of information. 

Here is a sample text file that I want to convert to 1d array. Any help?

LabView 2020

0 Kudos
Message 1 of 3
(2,920 Views)
Solution
Accepted by topic author Limyx826

Use ReadDelimitedSpreadsheetFile...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 3
(2,894 Views)

If you use "read delimited spreadsheet", You have relatively few choices, and you also need to transpose such that the "first row" gives you the first column (or you need to play with delimiters). For integers, you get I64, which is typically wasteful. You don't need 8 bytes to represent small integers. (Your array elements would fit into a single byte!)

 

Probably more versatile would be to read the file as simple long string and then use "Spreadsheet string to array" with the delimiter set to a linefeed and the type set to a 1D array of your desired datatype (U8, I8, I16, ... U64, SGL, DBL, EXT, etc.)

 

Here's how that could look like (for I32). You can wrap it into a subVI or even make it a VIM where you can set the exact desired datatype.

 

altenbach_0-1597506049818.png

 

 

(You can look inside "read delimited file" and it really does not do anything different, except with fewer choices in the number of dimensions (2D only!) and datatypes (DBL, string, I64), and with a much more complicated read function that can deal with offsets, line counting, etc. Overkill for your example!)

0 Kudos
Message 3 of 3
(2,858 Views)