LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CSV change from single column into multiple columns

Solved!
Go to solution

This is probably a simple solution but I'm relatively new to LabView and I've gone brain dead. I have extracted data from multiple instruments during a test setup and formatted into spreadsheet arrays and written to a csv file. However the data is simply formatted into 2 columns (1 for the data name, 1 for data value) which is correct however it's not very appealing or easy to read. An example of what this looks like is attached as Sample.csv.

 

I've also attached a file called SampleIdeal.csv which is how I would like the data to be arranged. Or even better if I could extract the freq and create a column just for that it would be even better. I'm assuming this has to be done using another string to spreadsheet array but like I said I've gone blank. 

 

The data is written line by line during the test to a txt file which I then read from and convert to csv. I can use matching pattern to isolate the Channel data and assume from there it should be easy to separate into columns but cant figure it out. I've attached the vi I'm using to extract the channel data into individual spreadsheet strings.

 

Thanks for the help

Paul

 

 

 

Download All
0 Kudos
Message 1 of 7
(5,978 Views)

Array to Spreadsheet String can receive a 2D array as an input. This would allow you to use all of the lovely LabVIEW array manipulation tools to generate a 2D array that matches your Ideal file. This manipulation, you'll have to develop yourself to fit your needs.

 

An easy way to streamline the process is to create a template that you like and then insert the data where needed.

 

You may also want to look in to the TDMS file format and use it in conjunction with the TDMS Add-on for excel.

 

To clarify regarding the 2D array, if you generated an array like below and wrote it to file, it would come out the way you want.

Extract Channel Data_BD.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 7
(5,966 Views)

Thanks for the advice.


I'm trying to create the 2d array. I figured the easist way would be to do a "Read from Spreadsheet File" and create a 2D array of each channels info that way. Then I initialize a 2D array the size that I want. Finally I use insert array to insert my 2D arrays into the newly created array. However this isnt working, the total_array stays empty. Any ideas?

0 Kudos
Message 3 of 7
(5,943 Views)
Solution
Accepted by pdpeterson87

Please include a Snippet of your code, so that we can better assist you. It's much easier to play around with your code using a snippet instead of a screenshot.

 

  • You don't need to use the Read from Spreadsheet VI 5 times. You can use it once to get one large 2D array of data and then parse the array for the sections you've hard-coded in there. Opening and closing the file over and over is slow.
  • Insert in to array will shift all the data around and make the array larger, so there's no need to initialize the array to that size at the start. Replace Array Subset might do what you're actually trying to do there.
  • You're having a basic problem with dataflow. The wires in LabVIEW are the vessels to pass the data and don't hold any reference to the indicator that you've wired to. You need to wire the output of the array operators to that array to update the indicator. 

LabVIEW programming is based entirely on dataflow and parallelism. This is incredibly powerful and has lead to its success over the years (coupled with the graphical programming), but is usually one of the first things that new developers stumble over. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 7
(5,936 Views)

Ok got it. I think I've made a bunch of improvements now. The data flow appears to be correct (by stepping through and placing probes I can see the data being filled in proper order). The new 2D array is correctly setup with the data being properly applied to new columns. However...the new array does not fill more than 25 rows. I'm assuming this has something to do with the fact that the first array I insert is only 25 rows so that is the max it is allowing. I thought the insert into array block would add as necessary though?

0 Kudos
Message 5 of 7
(5,916 Views)

Your assumption is correct. You can also utilize the Build Array node (and probably the Transpose Array node if things get tricky) to generate an array without initializing it first.

THe easiest way to fix the 25 problem is to use an Array Size node or two to figure out how big the array will need to be in the end and initialize it to that. If you go on with Insert Into Array, you may end up with empty array cells on the border. This is okay most of the time, I'm just picky.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 6 of 7
(5,909 Views)

Got it thanks! If I initialize an array to the correct size ( I can be fairly accurate because I know how many data points I am reading) then all the data is correct. You're right it may not be the cleanest solution but it will work for what I need at the moment.

0 Kudos
Message 7 of 7
(5,904 Views)