Showing results for 
Search instead for 
Did you mean: 

Obtain Max value of an array in a while loop, BUT with a change in an input variable

Hello good afternoon,


I am new at this forum, and quite new into LabVIEW. This time, I am trying to get the Max value (Velocidad Máxima) of an array that is filled out with the data from an equation to obtain velocity.


The fact is that we have to be able to change the input values and the program should continue running, showing the changes in the results. I belive I have achieved that part for the graph, the "R" output and the "Radio de manivela (cm)" output.The problem is that if the velocity (Velocidad) input changes for a lower value than the one tested, the Max value for the velocity remains the same as the last one.


For example, if the initial velocity is 3000 rpm, I obtain a Max velocity (Velocidad Máxima) of 7.1314; if I change to 5000 rpm the Max value adjust to 11.8936. But if I return to 4999 or less, the Max value remains as 11.8936


I think that maybe an option would be to reset the array to zero every time one of the inputs changes, but honestly I do not know how to do that.


Any help, will be really appreaciated. The values to use in the inputs can be whichever you want.

0 Kudos
Message 1 of 8

Your code may be riddled with race conditions due to the serious abuse of Local Variables.

You are writing to and reading from Locals within the same loop.  There is no way to set an order of execution; in other words, the dataflow is broken.


A quick solution is to delete ALL Locals Variables (with a promise never to use them again) and to simply wire the controls directly to the Formula Nodes.


To learn more about LabVIEW, I suggest you try looking at some of these tutorials.  You need to learn the dataflow aspect of LabVIEW.

Message 2 of 8

I modified your code.

I did not try to see if it worked, just got rid of all those bad Local Variables.


0 Kudos
Message 3 of 8

In addition, you are writing a control to a local variable of itself. That is just pumping hot air and makes absolutely no sense.


You seem to want to keep track of the maximum value. Also here you are making huge mistakes. First you append the value to the front of an array (which is much less efficient than adding to the end of an array). Then you keep the array in an uninitialized shift register, meaning that you retain old data between runs. Then you are growing the array forever, (or until you run out of memory). All you need to keep is a scalar value containing the current max!


Here's a quick cleanup attempt showing some techniques. I did not check your (or my) math, so you are on your own there. 😉


0 Kudos
Message 4 of 8

That's a nice clean(er) code.  I didn't move the unused one out of the loop simply because I did not know if there was someting missing for the code..  Obviously there is, otherwise why would someone create controls/indicators..


I didn't look at the equation at all, or attempt to analyze it.  The brain has been on vacation since yesterday afternoon..

0 Kudos
Message 5 of 8

First of all, thank you both for the prompt answer.


I know I still need to understand many concepts from LabVIEW, but I will try to keep on working on them.


You are also right about the fact that this data is just like a 1/4 of the code I need to work on, that is why there are so many input variables.


Nevertheless, I applied the changes you proposed but I still find the same problem. If I use 5000 rpm and then lower them to 1000 rpm, the Max velocity does not adjusts, even with the "-Inf" for initializing the shift register.

0 Kudos
Message 6 of 8

If you start with 5000 and then lower it to 1000, the max will stay at 5000. Why would it need to adjust??


You simply need to reset the max whenever the relevant input changes. A feedback node is easiest for that.


I cannot tell what you are doing, because I don't know what settings you are using for all the controls. Please fill them all with typical values, then make the new value the default before saving.


Here's what you could do to reset the max whenever the RPM changes. Modify as needed. 😉

0 Kudos
Message 7 of 8

Great!!, With that I have been able to work my way for the program right now.


I was checking my first post, and I left out an important piece of information, all the input data is for a combustion engine, really small (for a modeling airplane), and that is why we have to keep on varying the inputs (for more or less). We have to able to see how does the change in one parameter affects the others. 


Thank you so much!!!



0 Kudos
Message 8 of 8