LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting Data in Array

I have recently started using LabView. I have an application where I am trying to count the number of times a piece of boolean logic goes false. If it happens 4 out of 6 times I want to stop the program. I was thinking of doing this by using an array, and storing the last 6 conditions, just not sure which array is best suited to do this or if I should possibly use something else.
0 Kudos
Message 1 of 8
(3,498 Views)
Hi,
You can use a numeric indicator. Initialize it to zero.
When the boolen turn false increment it by 1.
Compare it by 4 and do whatever you want to do when its value is more than 4.
Use the Increment function from functions palette.
Let me know if you need more details or help.
 
Regards
CLAD
Using Labview 5.1,6.1,7.1.8.0
Message 2 of 8
(3,493 Views)

There's a lot of different ways to do this. If you go with numeric increment, you'll also have to clear it periodically if you only want to check the last 4 out of 6. One way is with a shift register. If you drag the shift register on the left side down, you get previous iterations. Then it's just matter of counting how many of the previous iterations and current are true. Here's an example.

Message Edited by Dennis Knutson on 10-16-2006 12:44 PM

Message 3 of 8
(3,487 Views)
Thanks for the help.  Anyother suggestions without using a shift register that can count the last 6 times? Also is it necessary to wire the false constant to the shift register? Maybe I missed something here.
0 Kudos
Message 4 of 8
(3,441 Views)
Why would you be averse to using shift registers?  Dennis' approach is probably the most simple.  The false constant is not absolutely necessary, but it is good practice.  It is wired just so that you know the initial state of the registers with absolute certainty.

Other implementations could make use of queues, but that is no less complicated than Dennis' solution.
0 Kudos
Message 5 of 8
(3,433 Views)
Thanks.  Dennis' approach works fine, I was just curious as to other ways this could be done. I had one other question. I am using a Write to Labview Measurement file VI also, but each time it is given the signal to save it just writes it in the same file. Is it possible to write to a new file every time? I have the VI inside a while loop. If you need more detail I can show you the program.
0 Kudos
Message 6 of 8
(3,401 Views)

Sure there other ways. You can create a queue of 6 elements and each iteration dequeue all of them. You can create an array with only 6 elements and discard the oldest. I think the shift register is about the most straight forward to implement and it's pretty obvious what is going on by just looking at the diagram.

Look at the 'Action' options in the Express VI. If you've chosen the save it to one file, you can also select 'Use next available file name'. You can also select 'Append to File' so that you have one file with multiple results. The other option is 'Save to series of files'. Click the hlpe button for further information. You can also wire something up to the File Name input of the Express VI if you want to do some file name creation in your VI.

Message 7 of 8
(3,397 Views)
You can also use an array as a ring buffer so you avoid memory allocation/deallocation.  Overwrite an element every time through and sum the result to check for exit.  This has probably already been mentioned.

Message Edited by DFGray on 10-20-2006 08:06 AM

0 Kudos
Message 8 of 8
(3,365 Views)