06-28-2010 01:16 PM
Hey Guys!
The first problem that I am having is converting my string file over to an array. I have a string file that displays the date in the fist column, time in the second, and collected data in the columns following. I have each column seperated by four spaces so I am using that as my delimiter when converting the string to an array. The problem is that only the first number of the date and the first number of the time are put into the array (because of the / and the : ) so I can't see the full date and time in my array. Also, once I have my array, how would I graph the date and time columns vs. another colum of data? I'd like to put the date and time as my x-axis and graph one or multiple columns of data vs. that date and time.
Attached is a picture of the string and a picture of the array developed from that string. Note: Only the 6 from 6/21/2010 is carried over.
06-28-2010 01:25 PM
You would appear to be converting to a numeric array and that is why you are not getting the correct date and time. You will have to convert to a string array and then index out the numeric columns before you can convert those to DBL. Index out the date and time and convert those to a time stamp. The Scan From String inside a for loop can be used. Convert the timestamp to a DBL and use an XY graph.
Next time, attach your code instead of a front panel. Can't correct something no one can see.
06-28-2010 01:53 PM
As indicated, you haven't shown us any actual code, so we have no idea what your code is doing. Not sure if you're using the Read From Spreadsheet File, or whether you're using the Read Text File function. If you're using the Read From Spreadsheet File you may find using the Read Text File function more convenient in this case. You can set it to read lines so you'll get an array of lines. Then you can auto-index a for-loop and use Scan From String to parse out each line. (Not sure if you're doing some insanely complicated string manipulations or simply using Scan From String.) As noted, your date and time column would need to be converted to a timestamp data type. Check the documentation on Scan From String, as it shows you how to do this. For example, something like this could parse the whole file quite efficiently:
06-29-2010 08:00 AM
Below is the code that I tried to use to put the above string into an array. The array that I get out is the one above where the full date and time cannot be seen. The delimiter is the four spaces between each column.
The subVI in this code is just an input of the string that I parsed before.
06-29-2010 08:54 AM - edited 06-29-2010 08:58 AM
All that does is to try to convert each value in each column to a floating point number. Think for a minute. How exactly do you expect to convert the string 06/21/2010 to a floating point number? Answer: you can't do it directly. There's no magic involved here. You have to explicitly parse it as a date string and use a timestamp data type. Please review the Scan From String function in the LabVIEW Help, as well as looking at the code I posted.
Also, the correct format string is "%s" (lowercase) for converting to a string. Though I don't think this function cares about this specific format string, in some cases the capitalization matters. To convert from a string to a number you want %f. Again, read the documentation.
07-01-2010 07:56 AM
smercurio_fc,
I tried your example code and it didn't work. My biggest issue is that I have both string files and numerical values that I need in my array. It is hard for me to attach any code because I simply don't know where to start. The first two columns are the dates and times that the data was taken. The following columns have the data collected at those respected times. In the first row is the title of each column including the channel number and units. The string that I attached above is the string that I get as a result after I am done parsing the entire data output. What I have to be able to do is place that in an array so that I can export it to an Excel Spreadsheet where we can graph the date and time vs. all the data points with their channel labels. When I do this, only the channel numbers are being exported and not the units. I know this is simply because the array is a numerical array and not a string array and it is exporting the numerical values and not the string values. I understand that I need to index each row/column that's in the string,convert it, then append it to an array but that is where I am stuck. Also, is it possible to just convert the entire array to a string array? If I need the data points, then I could always convert to a number after. If you could provide sample code that would be much appreciated.
07-01-2010 08:56 AM
@Fonzie1104 wrote:
smercurio_fc,
I tried your example code and it didn't work.
What didn't work? What did you get?
My biggest issue is that I have both string files and numerical values that I need in my array. It is hard for me to attach any code because I simply don't know where to start. The first two columns are the dates and times that the data was taken. The following columns have the data collected at those respected times. In the first row is the title of each column including the channel number and units. The string that I attached above is the string that I get as a result after I am done parsing the entire data output.
Well, this had to have been done with some code right? So upload that.
What I have to be able to do is place that in an array so that I can export it to an Excel Spreadsheet where we can graph the date and time vs. all the data points with their channel labels. When I do this, only the channel numbers are being exported and not the units. I know this is simply because the array is a numerical array and not a string array and it is exporting the numerical values and not the string values. I understand that I need to index each row/column that's in the string,convert it, then append it to an array but that is where I am stuck.
Now I'm a little confused. Are you starting with a file or with a string? You said initially you have a "string file". If you're starting with a file why are you reading it in LabVIEW as opposed to simply opening it directly with Excel? Also, "channel numbers" and "units". What are these? What units? I don't see any units in the screenshots you posted.
Also, is it possible to just convert the entire array to a string array? If I need the data points, then I could always convert to a number after. If you could provide sample code that would be much appreciated.
What array?
I'm sorry, but I'm just a little confused as to what you're trying to do. All you've shown us is two pictures of a big string and a 2D array. I have no idea what your source is, how that string came to be, or how that array came to be.
07-01-2010 10:05 AM
What didn't work? What did you get?
Your example code didn't work. I executed it as shown and nothing was displayed.
Well, this had to have been done with some code right? So upload that
The original Test File and the parsing VI are both attached at the bottom. The VI is very messy but it does what I need it to do and the problem isn't there.
Now I'm a little confused. Are you starting with a file or with a string? You said initially you have a "string file". If you're starting with a file why are you reading it in LabVIEW as opposed to simply opening it directly with Excel? Also, "channel numbers" and "units". What are these? What units? I don't see any units in the screenshots you posted.
I start with the Test File that is attached which cannot be imported into an Excel spreadsheet otherwise that would have been done to begin with. I need it in a specific format and that is why I have parsed it the way I have. The string file that is shown above is the format that I need and that was created from the Test file. And the units are there. If you look at the first row, there is a channel number followed by the units in parenthesis. Channel 104 is a DC voltage.
What array?
The array that would be created from the string.
I'm sorry, but I'm just a little confused as to what you're trying to do. All you've shown us is two pictures of a big string and a 2D array. I have no idea what your source is, how that string came to be, or how that array came to be.
I simply can just import my created string file into a spreadsheet without everything getting messed up. As of right now the only source that has to be worried about is the string that I have created which needs to be converted to an array so I can simply use Excel to create the necessary graphs. As I said before, the first two columns and the first row of the array that would be created need to be string values and the rest numerical values. If I can make the entire array just string values then that will work also. I just need the time and date to import into Excel in the right format along with the header row.
07-01-2010 10:12 AM
This should work. It will prompt you for the file path then give you a string array.
07-01-2010 10:15 AM
I am running LabVIEW 8.6