LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create an array of indices of certain elements in array

I have a 1D array and want to create a new array with the indices of the elements that are zero in the fisrt array.

The indices of the element that are zero shall be elements in a new array

Tom
0 Kudos
Message 1 of 4
(2,861 Views)
Hello Tom
There are different solutions to your problem.
This is one of those if searching only indexes for an element.
See attached doc

Hope it helps
Alipio
---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
0 Kudos
Message 2 of 4
(2,861 Views)
Run your first array into a for loop with indexing enabled. Add a shift register to the for loop and wire the left input with an empty array. Wire the indexed elements of the test array into a =0? (Comparison pallate) vi. The output should control the case of a case structure. The false case should run the "shift register array" strait through to the right half of the shift register. The true case should use the build array (make it 2 inputs) function with the "shift register array" wired to the top and the index of the for loop wired to the bottom. The output goes to the same output as was run through in the false case. The output shift register of the for loop should be what you are looking for.

I would send you a vi, but it is not very easy g
etting files on this computer. Sorry. If you need a sample vi, please respond and I will get one sent to you.

Hope this helps.
Russ
Message 3 of 4
(2,861 Views)
I ran into a similar problem yesterday and found a solution similar to what Russ suggested.

I am including a diagram of my solution, which replaces Russ' case structure with a Select. When the array element is not zero (True), the shift register input on the right side receives the shift register output from the left side. However, when the element is zero (False) I first add the current loop index to the array stored in the shift register.

For a large array, my solution may be slower than what Russ suggested. However, I like not having an unnecessary case structure.

Scot
0 Kudos
Message 4 of 4
(2,861 Views)