From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building Array With Multiple Indicies

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.

0 Kudos
Message 1 of 10
(2,818 Views)

"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). 

0 Kudos
Message 2 of 10
(2,814 Views)

Would it be best to do this inside a for loop or inside the while loop? Thanks

0 Kudos
Message 3 of 10
(2,797 Views)

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

0 Kudos
Message 4 of 10
(2,790 Views)

@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.

0 Kudos
Message 5 of 10
(2,779 Views)

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.

0 Kudos
Message 6 of 10
(2,759 Views)

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

0 Kudos
Message 7 of 10
(2,754 Views)

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.

0 Kudos
Message 8 of 10
(2,743 Views)

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

0 Kudos
Message 9 of 10
(2,707 Views)

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.

 

0 Kudos
Message 10 of 10
(2,704 Views)