12-07-2018 02:43 PM
Hi All,
I am trying to figure out how to hold a integer value in Labview while the program is running for use later on.
In the attached VI, I am generating a random number (from 0-1) and subtraction it from the random number generated in the next iteration. If the subtracted value, say X, is above .2, I would like to hold the value of X for the following iterations until a subtracted value less then .2 comes along. Example:
Difference Between Iterations Number Held
.1 0
.3 .3
.5 .3
.6 .3
.4 .3
.3 .3
.1 0
.19 0
.6 .6
.9 .6
.8 .6
.1 0
In the big picture, for the program I am writing, I would like to know the duration for which the number was held (in the example above, value=.3 was held for 5 iterations) and the amount of work done during that duration (area under the curve when the number are logged on a graph vs time).
I know it can be done using one of the structures. I tried using an Event Structure and Case Structure; I just don't know Labview well enough to know how to properly utilize them.
Thank you for your time.
Solved! Go to Solution.
12-07-2018 02:50 PM
You already have the answer in your code. Use another shift register. Loops can have more than one shift register.
12-07-2018 02:59 PM
How would I do that? Connect a shift register through some type of boolean function?
12-07-2018 03:02 PM
Yes, that would be how you would do it. Wire the value through one case and update the value in the other.
12-07-2018 03:30 PM
Now I am completely confused. Like I said, apart from while and for loops, I don't really know how to use structures properly.
Attached is an update of the VI with me trying to incorporate your advice to the best of my knowledge.
12-07-2018 05:16 PM - edited 12-07-2018 05:18 PM
@yoshi123 wrote:
In the attached VI, I am generating a random number (from 0-1) and subtraction it from the random number generated in the next iteration..
You cannot predict the value from next iteration. All you can do is operate on the current and previous value. Can you rewrite the problem in these terms?
(You latest code is not good. For example you are not "holding" any value and there is absolutely no need for local variables (it causes race conditions). There is also no need for an expanded shift registers with two histories. All you need is the current and previous value. Also, please give your indicators intuitive names to clarify the content)
12-07-2018 05:40 PM - edited 12-07-2018 05:43 PM
See if this can give you some ideas. You might have to change the comparison logic depending on the requirements.
12-08-2018 06:52 AM
@yoshi123 wrote:
Now I am completely confused. Like I said, apart from while and for loops, I don't really know how to use structures properly.
When you enter the LabVIEW Forums, the first Training Resource, "Learn LabVIEW Basics", has four short sections under Programming in LabVIEW. Section 7, Passing Data between Loop Iterations, might be useful for you. Indeed, spending some time with the Tutorial material and trying some simple examples yourself (what I call "experimenting") should work wonders ...
Bob Schor
12-10-2018 02:33 PM - edited 12-10-2018 02:34 PM
Thank you altenbach. Your VI modifications cleared up a few concepts for me.
Thank you all for your inputs.