LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Recording to Excel

Hello, I have been tasked to create a sub VI that will take data from four matrices and record data for any varying amount of time into one .csv file.  The data should have a time associated  with each iteration and the data in each matrix can vary from 1 to 42, but not necessarily in order.  Basically each header has to be configurable (from P1/T1 to P42/T42).  The screenshot below is how I want the excel spreadsheet to look like.  I have been working on this for several weeks, but to no avail.  I have been able to input headers (hard coded) and get on of the matrices data in, but as soon as I add a second matrix it throws its data in the next column next to matrix 1's data.  I am practically a new user of labview, so there may be a easy solution, but I have not been able to find any.  Also, the sub VI is within a loop, so I don't know if that affects the code a lot. Any help provided would be greatly appreciated!

Created Format Example.PNG

0 Kudos
Message 1 of 5
(2,058 Views)

Thank you for not including pictures of your LabVIEW code.  However, by looking at the code that you failed to attach, I'm forced to guess you might be using an Express VI do to your writing.  Or it is possible you didn't right-click the Write Delimited Spreadsheet function and choose Help, reading the Detailed Help.

 

Here's a Snippet showing you how to "do it in steps" (I'd strongly recommend you "do it in a loop" instead).  I tried to also attach the resulting CSV file, opened in Excel (incidentally, you are not "Recording to Excel", you are recording a Text File that "looks like" a Spreadsheet with rows separated as lines of text and columns separated by commas).  This code is simple enough you should be able to create it yourself, even if you don't know how Snippets work ...

Test CSV.png

Bob Schor

0 Kudos
Message 2 of 5
(2,032 Views)

Thank you for your response.  I was not previously using the Write Delimited Spreadsheet function but after using it, it seemed to help with a couple of my issues.  My main issue is I do not want the .csv file to start a new row for the header entries and a full iteration of the data.  I have attached two .csv files to, one shows what I want my code to format the spreadsheet like and the other is what it actually does.  I have also attached code this time.  Thanks again!

Download All
0 Kudos
Message 3 of 5
(2,015 Views)

Now I am really confused!  You've provided two examples of .csv files that look nothing like the (very-reasonably-formatted) picture you showed on your Original Post.

 

I'm going to try to answer the "Original Question".  I'm going to assume you have four Data Arrays, which I'll call "IP" (for Intake Pressure), "EP", "IT", and "ET".  Your Picture shows 7 measurements (e.g. P1 .. P7), each with multiple Time Points (Time X, Time X+1, ...).  I'm unsure if you have, say, 7 "stations" all collecting data at the same time, or if you have 7 repetitions of acquiring data from a single station, but I'm going to assume the former.

 

So you collect data from N Stations, taking K pressure and temperature readings simultaneously from each Station, and saving all of the data in 4 N x K Arrays.  For simplicity, I'm going to assume that you do this once, but if you set up another series of samples and want to add it to this .csv file, you could do that as well.

 

Here's how I would approach this.  The basic task is to write out an N x K Array, with Row and Column Headers.  (Oops -- I was about to tell you how to do this in Excel, using the RGT, then I remembered you are using Write Delimited Spreadsheet, but it's "almost" the same idea).  Because you are writing both Text and Numeric data (the header is text, your samples are numeric), you need to create a "Spreadsheet Array" that is (N+1) x (K+1), with the first Row and Column consisting of the Row and Column Header material that you want and the remaining N x K entries consisting of a String Array that represents the data in your numeric Data Array.

 

Trust me, you absolutely want to create a sub-VI that takes as inputs the Row Header (a K+1 String Array), a String (pattern) you can use to build the K-row Column 1 Header, and the N x K Numeric Data.  As with most well-written LabVIEW VIs, you should use the 4-2-2-4 Connector pattern, with Error In and Error Out on the lower corners.  I would also suggest you add a Boolean Input (I'd use the left top, not the left-top-corner, input for this) and call it "Append to file?".

 

So what does this sub-VI do?  You have the first row of your desired output String Array, the Row Header, so all you have to do is append the K rows formed from a column of the Column 1 Header array and a row of the N x K Numeric Data (which you pass through a For Loop to convert it from an Array of Numerics to an Array of Strings), giving you a row of Strings having K+1 Entries.  When appended to the Row Header, you have your (N+1) x (K+1) String Array that you send to Write Delimited Spreadsheet function, adding the "Append to file?" input.

 

Why the latter?  Well, the first time you call this little sub-VI with the (first) IP Array, you do not want to Append to File, but open a new one.  After that, of course, you want to Append. 

 

I hope all of this is clear, and that I'm not leading you too far astray.

 

Bob Schor

0 Kudos
Message 4 of 5
(1,982 Views)

Hi Elijah,

 

Of course, it's not impossible to do what you want (indeed, it may not be that difficult), but it would be simpler if you were happy to use a transposed array compared to your original image.

Would that be a possibility? (Edit: I note that your "Correct Example.csv" appears to do this)

 

If so, you can simply write the headers along the top row, and the append downwards by adding new lines for each measurement time.

 

If not, you'll need to keep jumping around your file to be able to append (or keep everything in memory and write only once at the end - potentially dangerous for long experiments, definitely problematic for large datasets in 32-bit LabVIEW). This isn't impossible, it's just harder than appending to the bottom of a file.


GCentral
0 Kudos
Message 5 of 5
(1,971 Views)