LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initialising Arrays

What is the best way to initialise an array within a while loop?
At present I use Initialise Array and put this within a Case statement. I
wire the loop counter i to the case statement such that when i=0 teh array
get's initialised else it just feeds straight through from registers (ie for
i>0) either side.
Trouble with this is that it seems to only work sometimes and the array does
not get initialised. The result is that I get an array of length zero. I
cannot understand why this is.
I also tries initialising outside the While loop feeding this into the
registe but this does not seem to work either. Any ideas?


Tom
0 Kudos
Message 1 of 4
(3,068 Views)
Since array initialisation is so often used everywhere, the probability for the problem to be in your code is 99.99%, coerced to integer.
Post a copy of your vi, that we might have a look.

CC
Chilly Charly    (aka CC)
0 Kudos
Message 2 of 4
(3,064 Views)
Maybe you could explain in a bit more detail what you mean by "initialize". Is the array size always the same? If it is always the same, you should initialize outside the main loop and feed the output to your case structure as a second input tunnel. Whenever you need to initialize, use a case where this input is wired to the output tunnel.

Obviously, the rest of your code modifies the array or you would never need to reset it. Most likely you have a bug elsewhere in the code where the array gets modified. Post your VI and we'll have a look!
0 Kudos
Message 3 of 4
(3,060 Views)
Hello –

It was not very clear to me what you mean by “the best way to initialize an array within a while loop”. I guess it depends on what exactly you are trying to do.

In general, you can initialize an array using the Initialize Array function located in the Functions >> Array subpalette. For that function, Dimension Size is the number of elements the array will have and Element is the value those elements will be initialized to. The number of Dimension Size terminals you have determines the dimension of the array.

If you post your VI and give more detail on what you are trying to do, I will be happy to take a look at it.

S Vences
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(2,997 Views)