LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to conditionally add elements to an array?

Hello Everyone,

 

I'm trying to use an array to store the time of an event like pressing a button. So "if" the button was pressed then store that time in an array, "else" the button was not pressed then continue. I can't seem to figure out how to do this. Below is some code I made that has the idea of what I want to do but not completely. "If" the button is pressed it displays the output of the time in a numeric indicator and "else" it just keeps displaying the previous time. I saw this post http://forums.ni.com/t5/LabVIEW/Conditionally-add-value-to-array/m-p/1974835/highlight/true#M653360 but I can't open the vi because it's a newer version and I don't understand what is happening. Your help is appreciated.

 

Max

 

true.png

false.png

0 Kudos
Message 1 of 5
(5,195 Views)

First of all, you don't have any arrays on your diagram. If you want to append to an array, use a "built array" node inside the case, and keep the array in the shift regsiter.

 

(You should also initialize your shift register. Also, you have a mismatch in datatypes. your indicator should probably be blue. You should also use a latch action boolean, not a switch.)

0 Kudos
Message 2 of 5
(5,185 Views)

Thank you for your help. The latch when pressed action is much better, now it doesn't gather up a bunch of times when the button is pressed. I'm close to having it, I think my loops are wrong or my array is wrong? It doesn't look like the I32 array in this tutorial: http://stackoverflow.com/questions/9863450/how-to-store-values-in-array-inside-loop except they are using a for loop, how would I implement a while loop?

true2.png

 

false2.png

0 Kudos
Message 3 of 5
(5,169 Views)

@mbigras wrote:

...I'm close to having it, I think my loops are wrong or my array is wrong? It doesn't look like the I32 array in this tutorial: http://stackoverflow.com/questions/9863450/how-to-store-values-in-array-inside-loop except they are using a for loop, how would I implement a while loop?

 


I don't see where you think what you have is wrong.  What part of your solution does not meet your requirements?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 5
(5,164 Views)

Because your loop counter is still incrementing even when you don't push the button. Also, your indicator is outside the loop so it won't update until you press stop.

0 Kudos
Message 5 of 5
(5,163 Views)