How to ensure equal probability of stim appearing on L or R of screen without hard-coding? Description inside.

Hi,
I am working on a task in Psychtoolbox where I'd like to display a stimulus 50% of the time on the left side of the screen, and 50% on the right side. Is there a way to ensure an equal balance of where the stimulus will appear without hard-coding? I would like it to be random (but always balanced) each time I run the task, but am not sure how to set this up. Thanks!

 Accepted Answer

50% turns out to be surprisingly tricky

4 Comments

Thank you for the link! I ended up searching around and settling on something quite simple...
% Target type (circle or square)
target_type = [ones(1,40) 2*ones(1,40)]; % Change based on number of trials
target_order = target_type(randperm(length(target_type)));
I think this code will allow me to present my two target stimuli an equal number of times (40 each), but in a random order for each participant. What I am stuck on now, and maybe you would have an idea...
I need to keep this balanced but random ordering for two sets of stimuli, with a twist. The first set consists of a circle and square, and the second, of two words. One shape and one word will be presented at the same time. I want the ordering/presentation of the stimuli to be "random", but I also want a certain shape and a certain word to appear on the same side of the screen 75% of the time.
I know all the basics of how to do this, but am unsure of how to set up that probability without hard-coding when and where each stimulus appears.
I hope that wasn't too confusing... thanks for any thoughts you might have!
scramble = @(v) v(randperm(numel(v)));
N = 40;
show_same_side = scramble([false(1,N), true(1,3*N)]);
side_to_show1 = scramble([1*ones(1,2*N), 2*ones(1,2*N)]);
side_to_show2(show_same_side) = side_to_show1(show_same_side);
side_to_show2(~show_same_side) = 3 - side_to_show1(~show_same_side);
Now the two will be on the same side 3/4 of the time and on opposite sides 1/4 of the time, with left coded as side 1 and right coded as side 2.
Thank you! I will go try to understand this now :) :) Immensely appreciated!!
Hi Walter,
You helped me with this code several months ago so I'm wondering if you could point me in the right direction with it! :)
I need to change the ratio of same side 3/4 and opposite side 1/4 to 2/3 and 1/3, respectively. It sounds super easy, but I don't think I'm getting the right output?
scramble = @(v) v(randperm(numel(v)));
N = 40;
show_same_side = scramble([false(1,N), true(1,3*N)]);
side_to_show1 = scramble([1*ones(1,2*N), 2*ones(1,2*N)]);
side_to_show2(show_same_side) = side_to_show1(show_same_side);
side_to_show2(~show_same_side) = 3 -side_to_show1(~show_same_side);
I changed the 3s to 2s... Is there anything else/different I'd need to do?
Thanks!

Sign in to comment.

More Answers (0)

Asked:

on 29 Dec 2015

Commented:

on 1 Apr 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!