LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Select function for arrays

Solved!
Go to solution

Hello, I am looking for a function similar to a SELECT function, but for arrays. 

I am trying to do the following: 

Let's say, 3 random numbers functions are compared to a value (of 0,5). If the condition (is bigger than) is TRUE, i need to switch on a button and hold logical ONE for the rest of the time - so I do not care about the value of random number after. It is important for me, that the condition was true once. So it is like a cummulative function of 3 led buttons, which tells me at the end, that the condition was fulfilled at least once for each of 3 comparisions (if all of the buttons are true).

I managed to do it for a single random number only, using SELECT function and SHIFT register, but I did not manage to do with arrays of numbers.

Maybe it is easy for someone of you a you can help me, because I am stuck :D....

If this problem has been resolved already, I am pretty sorry - but I could not find the keyword for describing my issue. 

Thank you very much and have a nice day.

Pinca

 

0 Kudos
Message 1 of 10
(6,583 Views)

Please provide what you've tried already so we can better understand and help portray back to you what we suggest.

 

Most everything that can be done with a scalar can easily be adapted to an array. Instead of Select, you could us Search Array for the first True value.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


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

Attach your VI you have so far.  That way we can see how you've started and can help you figure out how to become unstuck.

0 Kudos
Message 3 of 10
(6,578 Views)

Yeah I think I know what you want, but your description could be interpreted a couple of ways, code would make it more clear what you are trying to do when you use a scalar, and why it doesn't work when you use an array.

 

If you have 3 arrays, and you want to pick one, you could try to use something like this:

 

https://lavag.org/topic/16842-my-xnode-select-n-inputs/#entry109444

 

Note that the thread is primarily about an XNode select function which is unsupported, but that thread has useful information on selecting an array.

0 Kudos
Message 4 of 10
(6,541 Views)

Use an array ot three booleans in the shift register (initialized with an array of three False booleans).

 

Build an array of your three buttons and take the OR of the two arrays (one from the buttons and one from the left shift register and feed the output into the right side shift regsiter.

 

An "AND array elements" of the array will turn true once all elements are true..

0 Kudos
Message 5 of 10
(6,522 Views)
Solution
Accepted by topic author Pinca

Here is some simple code as described.

 

The VI will stop once all booleans have been true at least once. I set the condition to >0.98 to make it run a bit longer. Modify as needed.

 

 

(note that even in your original code, a boolean OR is significantly simpler than a "select" function.

Download All
0 Kudos
Message 6 of 10
(6,501 Views)

This is where I became stuck - for a single condition everything was ok (i clicked the button and ONE was held in the shift register for the rest of time.

For array, the appropriate values were displayed only but were not kept when no condition was fulfilled.

 

0 Kudos
Message 7 of 10
(6,448 Views)

Thank you very much altenbach. I will try to modify it for the situation, where I do not have the exact number of booleans to compare (between one and four). So I will try it. 

Pinca

0 Kudos
Message 8 of 10
(6,441 Views)

@Pinca wrote:

This is where I became stuck - for a single condition everything was ok (i clicked the button and ONE was held in the shift register for the rest of time.

For array, the appropriate values were displayed only but were not kept when no condition was fulfilled.


You array code does not contain a shift register at all. That's a critical ommission.

0 Kudos
Message 9 of 10
(6,424 Views)

Yes, I had it there before, but this was the only try that made a little sense - but using shift register in this case made it all doing wrong.

Thank you.

0 Kudos
Message 10 of 10
(6,387 Views)