LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you hold an int value in Labview?

Solved!
Go to solution

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.

0 Kudos
Message 1 of 9
(2,968 Views)

You already have the answer in your code. Use another shift register. Loops can have more than one shift register.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 9
(2,963 Views)

How would I do that? Connect a shift register through some type of boolean function?

0 Kudos
Message 3 of 9
(2,956 Views)

Yes, that would be how you would do it. Wire the value through one case and update the value in the other.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 9
(2,954 Views)

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.

0 Kudos
Message 5 of 9
(2,929 Views)

@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)

 

 

0 Kudos
Message 6 of 9
(2,916 Views)
Solution
Accepted by yoshi123

See if this can give you some ideas. You might have to change the comparison logic depending on the requirements.

Message 7 of 9
(2,908 Views)

@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

0 Kudos
Message 8 of 9
(2,885 Views)

Thank you . Your VI modifications cleared up a few concepts for me. 

 

Thank you all for your inputs.

0 Kudos
Message 9 of 9
(2,831 Views)