02-10-2009 03:36 PM
I have a .csv file which I would like to read into a 2D array in LV. The file is a mix of text and decimal values. I have attempted to use the "read from spreadsheet file" however it changes all text values to 0.00. I have tried to set the format of "read from spreadsheet file" to string (%s) but to no avail.
After several hours of searching these and other forums for a solution I have come up empty handed.
I look forward to hearing you thoughts.
Thanks a bunch!
Solved! Go to Solution.
02-10-2009 04:16 PM
If you post a copy of your VI and a copy of your CSV file, we maybe able to help you.
If you have a mix of text and decimal values, how do you want them to appear in LabVIEW. A 2-D array can only be numerics or strings, not both.
02-10-2009 04:16 PM
Do you have a reliable way of distinguishing which parts of the file are text and which are numeric data? Are they mixed on the same line or always on different lines? Do the text lines have some unique characters, preferably at the beginning or ending of each line? In other words do you have the format definition of the file?
Usually it is necessary to separate the text parts from the data parts using string functions and then either the string to number formatting functions or the Spreadsheet String to Array can be used to convert the numeric data strings to numbers.
Lynn
02-10-2009 04:46 PM
02-11-2009 07:23 AM
Thank you for your help!
There isn't much to the code. What I have described is my starting point.
The data is formatted in such a way that I know very reliably what is text and what are numbers. From the suggestions you've made I plan to read in all values from the csv as text. When I need to treat a value as a number I will convert it.
The data is similar to this in content but with many more fields:
Test 1, Test 2, Test 3
Yes, Yes, No
34.8, 42.6, 45.0
0.02, 5.43, 2.1
Is there a way to read two delimiters "," and newline? I suppose the "Scan String for Tokens" could be used. This would allow me to mimic the "read from spreadsheet file" function but for text values.
What do you think?
Thanks again for the help!
02-11-2009 08:34 AM
I did some more searching around and came across this post. It explains how to copy and modify the "Read from Spreadsheet File" to create arrays of strings instead of numerical values. All my data reads into lab view as text and I will simply convert text numbers to actual numerical values as needed.
Thanks again!
02-11-2009 09:39 AM
02-11-2009 09:48 AM
True statement Dennis. And in addition to that the post provided the idea that one could solve the problem in that manner. Something I hadn't discovered (nor had been suggested here).
Thanks again for your help!