02-09-2020 05:38 PM
Good evening Everyone,
I'm hoping for a little assistance. For my class I wrote a random number generator program, which works. In addition, I created a 2D array where the first row of 20 elements represents the random number created and the second row represents on which iteration the random number was created. With the 2D created in the labview, I'm now trying to write the data to an xlsx file. Currently, I'm using the write delimited spreadsheet node to achieve this goal, but without any success. I have attached my code in zip file.
Thanks in advance, pat!
Solved! Go to Solution.
02-09-2020 07:03 PM
Read the Help for Write Delimited Spreadsheet. It writes a text file, with columns delimited by (in your case,) commas, and rows delimited by New Lines (<CR><LF>). This is called a "Comma-Separated Values" (or .csv) file. You gave it an extension .xlsx, which (if you have Excel installed) Windows will try to send to Excel, although it is not what Excel expects as its proprietary file type, and Excel will (probably) throw an error. Try opening the file with NotePad or any other "text-only" routine -- you should see a perfectly nice text file.
Bob Schor
02-09-2020 07:24 PM
Hi Pat,
As Bob_Schor mentioned, you're telling Excel that you're writing a .xlsx file, when you're not.
If you really want to write an Excel file, you can look at the Report Generation Toolkit. However, if this isn't a strict requirement (and I'd guess it usually isn't!) you can instead just change the path to write a "Random_Number_Data.csv" file. Excel will happily open this. You can also reorder your array or transpose as necessary to get the 'shape' you'd like in your csv file (->Excel).
As a further note, if you'd like the Graph to update in real time (that is, during the execution of your generation) you'll want to put the graph (or chart) inside the loop.
In this specific case, a Chart will likely be much simpler to program (because a chart appends data up to a "History Length", configurable programatically or more simply by right clicking on the chart. You can then just connect the random number to the Waveform Chart.
For a Graph, you'd want to take a look at Shift Registers probably!
02-10-2020 06:20 AM
@Bob_Schor wrote:
Read the Help for Write Delimited Spreadsheet. It writes a text file, with columns delimited by (in your case,) commas, and rows delimited by New Lines (<CR><LF>). This is called a "Comma-Separated Values" (or .csv) file.
My personal preference is to use the tab (default) delimited format with a txt extension. Excel still opens these up just fine. I find the tabs easier to read in a text editor and it also works better internationally (there are countries that use the comma as the decimal separator).
02-10-2020 09:14 AM - edited 02-10-2020 09:15 AM
Good morning Bob,
Thank you for the quick reply. I did some more research with the detail help and was to get the program to work. I appreciate you pointing me in the right direction. I may have another question but I'm going to give it a whirl before I ask. Once again thanks for the assistance.
02-10-2020 09:21 AM
Hi cbutcher,
I would love to use a chart for this situation but my professor is requesting us to use a waveform graph. I appreciate the explanation on how to implement a chart for this situation, I did know how to get a chart to update in real time. I'm still playing with transpose function and trying to understand the function better. Thank you for the help!
02-10-2020 04:14 PM
Good evening everyone!
Before I dive into my questions, I'll provide some background regarding the code. I have been tasked with developing a random number generator that generates 20 values that will be written to a csv file. In addition, I must provide an input for users that allows them whether or not if they want to generate number random values or recall values from the csv file. This is where the write/read delimited spreadsheet nodes come into play. I have a few questions regarding the Write and Read delimited spreadsheet nodes. In regard to the write node, my data always starts in the second row of my csv file. Why is the data entry starting on the second row of the csv file? This is a problem because when I read the file, I get a row of zeros output in my 2D (it should be the random numbers). Also, my waveform graph comes out looking crazy when reading from the csv file, is there anyway I can clean this up? I have attached my logic and csv file in a zip folder. Thanks for the help everyone.
02-11-2020 02:13 AM - edited 02-11-2020 02:18 AM
A few thoughts (numbers for reference, not importance):
Note that when you append to an existing file, they will appear below the previous entries. With this layout, that means you'll plot them as multiple plots like this:
If that's not what you want, you might need to consider transposing the data.
02-12-2020 08:21 AM
Hi cbutcher,
Thank you for such a detail response. I'm trying to go through the logic and truly understand your modifications and the advice you offered. I do have one question, is there no logic in the FALSE state of the case structure?
Thank you for the help - Pat
02-12-2020 09:46 AM