LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use Previous Element of an Array instead of Zero

Solved!
Go to solution

I have a pretty simple task, I'm trying to make an array of 10 random numbers from 0 to 5. However, if a 0 is given from the random number generator, I want it to use the previous array element instead.

 

This seems to work if the random number type is "Random Number (Range) I64" but it doesn't work if it is "Random Number (Range) DBL". Why is this?

 

This can be seen in the example VI I uploaded.

 

In my actual program, it seems to work intermittently. I'm having trouble figuring out why.

0 Kudos
Message 1 of 8
(1,083 Views)
Solution
Accepted by topic author downerdce

The odds of getting exactly 0 from a Double is practically 0.  The odds of 0 for an integer are 1/6.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(1,077 Views)

Makes sense! My actual program I'm using this in also is using double's. I will try a threshold value instead.

0 Kudos
Message 3 of 8
(1,070 Views)

By the way, you can greatly simplify your VI using an Autoindexing tunnel to build your array and a Feedback Node (or Shift Register) to keep the previous value.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 8
(1,069 Views)

thank you! Can you do the same if you are referencing a previous iteration of the array with that type of shift register (feedback node)?

0 Kudos
Message 5 of 8
(1,054 Views)

@downerdce wrote:

thank you! Can you do the same if you are referencing a previous iteration of the array with that type of shift register (feedback node)?


I'm not sure what you are asking for here.  A Shift Register and Feedback Node will just return whatever the previous input to it was.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 8
(1,038 Views)

downerdce_0-1637695087960.png

 

When you're doing this to get the value from previous full iteration of a FOR loop...

 

0 Kudos
Message 7 of 8
(1,031 Views)

@downerdce wrote:

When you're doing this to get the value from previous full iteration of a FOR loop...

 


Nobody here would be doing "this". (attaching a truncated meaningless picture of useless code!)

 

  • Why is the shift register expanded to two histories?
  • Why is it not initialized?
  • What should happen if the first random value is zero (i.e. if there is no "previous element"?)
  • Why does the shift register contain a Boolean instead of the previous random number? 
  • Where do all the wires come from and where do they go?
  • Where is the rest of the code?
  • etc.

 

Please attach your VI if you want to get help!

0 Kudos
Message 8 of 8
(1,024 Views)