06-05-2017 12:12 PM
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]
06-05-2017 12:30 PM
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.
06-05-2017 12:32 PM
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
06-05-2017 12:40 PM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
06-05-2017 01:08 PM
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
06-05-2017 01:34 PM
So this is mine but index doesnt increases. So it just shows the value for index 0 !
06-05-2017 02:18 PM
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
06-05-2017 02:32 PM
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.
06-05-2017 02:54 PM
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.
06-05-2017 03:10 PM