LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to present each case in a case structure a certain percentage of the iterations

Solved!
Go to solution

I am programming a task for use in a psychology experiment. There are two options for the stimulus, the test and the catch stimuli. I want to present the test stimulus on 90% of the trials and the catch stimulus on 10% of the trials. Right now, I have the test and catch stimulus as two cases in a case structure and I have that case structure in a for loop so I can control the number of trials. I cannot figure out how to make the test stimulus run on 90% of the iterations. 

0 Kudos
Message 1 of 14
(4,283 Views)
Solution
Accepted by psloan21

Ignoring any functions for randomizing data which probably exist in LV, here are a couple of options:

 

  1. The "sort of" one - you don't know how many iterations you will have and you want to choose between two options at a probablity of 10% and 90%. Take the random number generator and check if the result is larger than 0.9. It will be 10% of the time (at least close enough for something involving human interaction, which presumably has a limited number of runs).
  2. You know how many iterations you have and you want an exact number - generate an array of booleans of size N initialized to F. Divide N by 10 to get your 10 percent and then use a shift register to replace specific elements in the array. The elements you replace should be a random number multiplied by N and rounded and you should also have a while loop in the for loop to regenerate a number if there is one you already picked.

___________________
Try to take over the world!
0 Kudos
Message 2 of 14
(4,276 Views)

3. Generate an array with the needed quantity of T and F and run it through Riffle.vi

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 14
(4,211 Views)

Where is the Riffle VI? 

0 Kudos
Message 4 of 14
(4,169 Views)

Signal Processing->Signal Operation



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 5 of 14
(4,161 Views)

Hi psloan,

 

you could use Quickdrop to find it - or search the LabVIEW help for "Riffle"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 14
(4,159 Views)

You can't use Riffle to riffle a boolean array after all, but you can pretend.  This doesn't provide fractional True values, so if you wanted 45% True you'd actually get 50%. 😛

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 14
(4,108 Views)

We are making things too difficult here.  Let's pull out a trick from the bag of Altenbach.  Use the Bernoulli Noise VI (found in the Signal Processing->Signal Generation palette).



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
Message 8 of 14
(4,092 Views)

Maybe the probability of a "1" is valid for each element, but I don't think this is what the OP wanted.  This example should have five Trues, no?  I couldn't get it to fill it with 15 Trues, but 14 happened pretty quickly.

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 9 of 14
(4,073 Views)

@crossrulz wrote:

We are making things too difficult here.  Let's pull out a trick from the bag of Altenbach.  Use the Bernoulli Noise VI (found in the Signal Processing->Signal Generation palette).


I was just about to post that... 😄

0 Kudos
Message 10 of 14
(4,056 Views)