04-15-2018 12:30 PM
Hi,
I want to build an array from the output data from the program below. I understand that I need to build the initial array from the values I have (iterations, temperature, led color, and message). However, I want to add a new index for each run (1 second between run), so that I could have an array like the following:
1, 60, Green, No Warning
2, 100, Red, Heatstroke
and continues.
How would I go about doing this? I have tried a for loop and index array function to no avail. Thanks for the help in pointing me in the right direction.
04-15-2018 12:44 PM
"index array" is the wrong function here. You need a shift register initialized with an empty 2D array, then append a new row with each iteration using built array. This seems to be related to your other question. Instead of building the array in memory, it would probably be more reasonable to just append to the file inside the loop (the loop is slow enough here).
04-15-2018 01:20 PM
Would it be best to do this inside a for loop or inside the while loop? Thanks
04-15-2018 01:32 PM
It depends. Do you have experience with any other Programming Language? Many (including LabVIEW) have two types of Loop constructs -- one that runs until a condition is True (LabVIEW's While loop, other language's DO .. Until or While .. DO loops) or one that "counts" iterations (usually called a FOR loop). If you want to create an Array of (exactly) 10 elements, it is simpler to wire "10" to the "N" input of a FOR loop than to test the While Loop's Index ("i") to see if it is equal to 9 ("9? Why not 10?" I hope you know the answer to this). If you don't know in advance how many times you need to run the Loop, a While loop is a simpler method to use. [Warning -- there's a Trap for the Unwary in the previous sentence].
Bob Schor
04-15-2018 02:22 PM
@CSJeff98 wrote:
Would it be best to do this inside a for loop or inside the while loop? Thanks
You don't even have a FOR loop, so why the question?
A FOR loop is only appropriate if you know the final number of iterations before the loop even starts. If you need to decide while the loop is running, a while loop is correct. (Minor exception: You can terminate a FOR loop early using a conditional terminal)
Tunnels default to autoindexing on FOR loops but to PLAIN on while loops, but the tunnel type can be changed as needed in both cases.
04-15-2018 03:39 PM
I believe I need to add a for loop. I have tried numerous things with arrays and clusters, but still not getting the proper result. The generalization is that for each second, a number is generated, which causes a led to light up and a message to appear. I just want to build an array with all 4 elements for each second (each iteration) and write it to a delimited spreadsheet file. It doesn't seem that hard, yet I still cannot get the results I want.
04-15-2018 04:28 PM
I believe I fixed the output array into writing the file. However, when I try to read the file (string values) in a different program, i get an array that shows various symbols. I am not sure why this is the data I get. Thanks
04-15-2018 06:38 PM
You are trying to read a *.vi file instead of the output file.
Any other program is "different", so it would help to be more specific.
04-16-2018 10:36 AM
My apologies for not being more specific. I open another instance of Labview to read the output data and I get an array of various symbols as shown in my previous reply. How do I go about reading the output if I need to specify the original file path? Thanks again
04-16-2018 10:42 AM
What is the exact file name of the file you are writing?
What is the exact file name of the file you are reading?
When reading, you are obviously specifying the file name of the VI (code) instead of the name of the data file.