LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to turn this pseudo code to labview

I'm wondering how I can show an array's value every T second. I'll attach what I have so far as soon as I get on my laptop . but basically this is my pseudo code

for T=0 , T<5 (lets say every 5 second) , T++

      for i=0; i<array.size() , i++

                print array[i]

 

0 Kudos
Message 1 of 14
(4,987 Views)

I don't understand the T for loop.  Are you wanting to change the amount of time between each print?  You basically don't want to use a for loop but rather a while loop.  The loop runs continuously, checking the elapsed time on every iteration.  After the first time target is reached, output the first index.  You can't autoindex in a situation like this so the index should be kept in a shift register and incremented after each time target.  Stop the loop when all elements have been printed.  I left that undone.Example_VI_BD.png

aputman
Message 2 of 14
(4,961 Views)

Sorry for confusion..no I want every T second this loop get repeated..so every T second, one by one values of the array get displayed

0 Kudos
Message 3 of 14
(4,957 Views)

You could have a for loop, but with the wait your code will wait there and do nothing for that amount of time, and you may want to check things like the request to exit, or other UI functions.  For this reason I think the while loop is the best answer.

Message 4 of 14
(4,950 Views)

I would second the implementation presented by aputman. A while loop that implements wait using the elapsed time VI is an easy, lightweight solution to your problem. To answer your specific follow-up question, this is precisely what aputman's solution does. The while loop will repeat execution indefinitely and, each T second increment (here set to 5 seconds), the elapsed time express VI will return true and the true case in the case structure will execute, printing the currently specified index in the array and incrementing that index. Also, each time T seconds has elapsed, the elapsed time express VI resets itself and begins measuring the next T seconds. Now, in your implementation, you will likely need to bound the array indexing value if you wish to create useable output, but that will be specific to your input array. I hope that helps explain what is happening in aputman's solution, but feel free to post any additional questions you might have!

 

Duncan W

Message 5 of 14
(4,922 Views)

So this is mine but index doesnt increases. So it just shows the value for index 0 ! 

0 Kudos
Message 6 of 14
(4,911 Views)

Sorry..I fixed the problem..I have one more question..It currently showing values of the array but it doesnt repeat in a loop..any idea why?

ETA: # of intervals is number of values is number of values in the array

0 Kudos
Message 7 of 14
(4,892 Views)

There's a couple of things we probably want to clean up in this VI in order to accomplish your goal. First, I would remove the number of intervals control entirely. You are using it to index the second dimension of the input array, but the array is only one-dimensional. Basically, it isn't doing anything right now. Now, to answer your question about looping the array index, I would recommend comparing the index against the size of the array during each iteration of the true case and, if it is equal to the size of the array, reset it to 0. Right now, the index is incrementing indefinitely and you are trying to index into a part of the array that doesn't exist once the index is larger than the size of the array. I would be happy to draft some prototype code if this explanation is lacking.

 

Duncan W.

Message 8 of 14
(4,879 Views)

Not sure what you are looking for exactly.  However, I expanded some on your design to highlight what you may have missed.  It is working depending on the following.  The array needs to be pre-loaded and the run button must be pressed in order for the value to update.  Also, to avoid array overrun, I rolled the index based upon array size.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
Message 9 of 14
(4,872 Views)

loop.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 10 of 14
(4,861 Views)