LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create string array from text file

Hello all,

 

I am trying to fill a 2D array with values from a text file. Simple enough, right?

The problem is, I need to take values from each line and rearrange them before adding them to the array.

 

Here are the contents of the text file:

"SHGC0" 0.005771 0.007884 0.009891 

"SHGC1" 0.662647 0.600662 0.541796
"VT0" 0.000000 0.000000 0.000000
"VT1" 0.656876 0.592777 0.531905

 

I need to "columns" of data and transpose them into rows, ie. [0.005771, 0.662647, 0.000000, 0.656876]    (first column)  and then place them end to end (would end up with 1 row, 12 columns).

 

The text file above would end up looking like this: 

[0.005771, 0.662647, 0.000000, 0.656876, 0.007884, 0.600662, 0.000000, 0.592777, 0.009891, 0.541796, 0.000000, 0.531905]

 

Please note - the data will always have 6 decimal places, but the values will change depending on the text file.

    - the text file is provided by a program and is not tab delimited, so making it into a spreadsheet would not help.

 

Thanks,

Laura


0 Kudos
Message 1 of 4
(4,650 Views)

Yes, converting to a spreadsheet is going to be the easiest approach here.  Just set the delimiter to a space (there's a constant for this in newer LabVIEW versions, but a string constant containing a space is fine too).  Assuming the initial string will never contain a space, you can read an array of strings, delete the first column, then do some array manipulation (I'm thinking transpose array and reshape array here) and convert to floating point.  If the initial string might contain a space, then you can do the same thing but line by line, removing the string and then reading an array of floating point values.

0 Kudos
Message 2 of 4
(4,642 Views)

Hi

 

Could you post your text file? We can try out the options available and then make a better suggestion.

 

If you have already developed a vi to read from the text file, post that too. We can see what the problem could be.

Regards
Freelance_LV
TestAutomation Consultant
0 Kudos
Message 3 of 4
(4,615 Views)

That's a fairly straightforward operation, since LabVIEW has a goodly selection of string and array manipulation tools.  The attached code is in LV 2010.

 

FileReadArrayManipulation.png

 

The VI reads the entire file (you may want to chunk this if you have a huge file).  Using the spreadsheet string to array primitive, this is converted to an array of strings using the space as a separator.  The first column is deleted, the array transposed, then reshaped to a linear array.  If you have further questions, let us know.

This account is no longer active. Contact ShadesOfGray for current posts and information.
0 Kudos
Message 4 of 4
(4,595 Views)