LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replacing elements in an array

I'm trying to do something that should be very simple, at least it is in languages like C++ and java so I assume it will be simple with G as well...but I'm new to LabView... All I'm trying to do is replace the existing contents of an array. I'm using the replace array subset vi. Basically I initialized all 10 elements of an array to 1. I then created a for loop which should replace the 1 of each element with the element number (in other words I connected the iteration terminal to the index and new element terminals). If I step through the code the element is temporarily replaced but then it goes right back to 1. I know I'm missing something simple. I've attached the vi.
0 Kudos
Message 1 of 4
(3,059 Views)
I can't read your vi (haven't gotten 6.1 yet..), but I would suspect that you're not using a shift register in your loop. Without one you are just passing the initial array into the replace function each time. To add one right-click on the loop and select shift register. Wire your initialized array to the left terminal of the shift register outside of your loop. Then connect the left terminal to the input of the replace array subset function and connect the output of the function to the right terminal. This way new array from the replace function is passed back to the begining of the loop for the next iteration each time the loop executes.

Attached is an example.

Brian
Message 2 of 4
(3,059 Views)
Thanks for the help Brian.
0 Kudos
Message 3 of 4
(3,059 Views)
HI Brian! Have the same Problem. I'm new to labview -> havn't really got into the shift register thing. Is there really no way to directly access an array element and modify it? (my problem:an array should count how often a die fells on a specific number).
Are there more exaples about that problem?
ANDY
0 Kudos
Message 4 of 4
(3,059 Views)