Welcome! Log In Create A New Profile

Advanced

Seeking advice on avoiding repetitive code with CircleGraphic() in Monkeylogic receptive mapping

Posted by younesvalibeigi 
Hi,
I want to build a receptive mapping code that shows circles at distinct locations for 100 ms durations inside the receptive field of a neuron. I am trying to use CircleGraphic(), but I would need to repeat this function for every circle that I want to appear. However, using create_scene() and run_scene() inside a for loop does not seem to work. Is there a way to present circles at various locations without repeating CircleGraphic() multiple times?

This is the code I wrote, but the lines inside the for loop do not show up during runtime:

% if ~exist('eye_','var'), error('This demo requires eye signal input. Please set it up or try the simulation mode.'); end
hotkey('x', 'escape_screen(); assignin(''caller'',''continue_'',false);');
hotkey('r', 'goodmonkey(70, ''juiceline'', 1, ''eventmarker'', 14);');   % manual reward

if exist('eye_','var'), tracker = eye_;
elseif exist('eye2_','var'), tracker = eye2_;
elseif exist('joy_','var'), tracker = joy_; showcursor(true);
elseif exist('joy2_','var'), tracker = joy2_; showcursor2(true);
else, error('This demo requires eye or joystick input. Please set it up or turn on the simulation mode.');
end

bhv_code(21, 'Fixation', 30, 'Stimulus', 100, 'Reward')
%editable('fix_rad','reward', 'reward_interval','grid_min','grid_max','stim_size','stim_time')
fixation_point = 1;


stim_time = 100;

fix = SingleTarget(eye_);
fix.Target = fixation_point;   % Use [X Y], instead of TaskObject#, since BoxGraphic is not TaskObject
fix.Threshold = 1.5;
wth = WaitThenHold(fix);
wth.WaitTime = 5000;
wth.HoldTime = stim_time;
scene0 = create_scene(wth);




box = CircleGraphic(wth);
box.EdgeColor = [1 1 1];
box.FaceColor = [0 0 0];
box.Size = [1 1];
box.Position = [-5 -5];
scene1 = create_scene(box);


run_scene(scene0, 10);
if ~wth.Success
    error_type = 1; % Success 
else
    run_scene(scene1, 20)
    error_type = 4;
end


for i=1:10
    wth2 = WaitThenHold(fix);
    wth2.WaitTime = 0;
    wth2.HoldTime = stim_time;

    box2 = CircleGraphic(wth2);
    box2.EdgeColor = [1 1 1];
    box2.FaceColor = [0 0 0];
    box2.Size = [1 1];
    box2.Position = [i i];
    scene2 = create_scene(box2, fixation_point);
    run_scene(scene2, 20);
    
    if ~wth2.Success
        error_type = 2;
    else
        error_type = 3;
        run_scene(scene2, 20);
    end

end



idle(0); % clear screen
trialerror(error_type);
set_iti(300);

Your code is not working as you think, because you did not write it correctly. See the lines that I colored in red.

Learn how to separate stimuli and behavior. There is no need to rewrite the entire chain every time. If you want to change the position of a circle, just assign a new coordinate pair to the Position property.
https://monkeylogic.nimh.nih.gov/docs_ScriptingScenes.html#GraphicAdapters

Take a look at CurveTracer to present the same circle at multiple locations sequentially.
https://monkeylogic.nimh.nih.gov/docs_RuntimeFunctions.html#CurveTracer
Hi,

Thank you, Jaewon. I rewrote the code based on CurveTracer. It worked perfectly for the first trial, but for all the following trials, only one dot is shown instead of the ten dots I have chosen. I tried modifying the sequence of objects (fix, wth, box, ct), but it did not solve the problem. Could you please guide me through this?


% if ~exist('eye_','var'), error('This demo requires eye signal input. Please set it up or try the simulation mode.'); end
hotkey('x', 'escape_screen(); assignin(''caller'',''continue_'',false);');
hotkey('r', 'goodmonkey(70, ''juiceline'', 1, ''eventmarker'', 14);');   % manual reward

if exist('eye_','var'), tracker = eye_;
elseif exist('eye2_','var'), tracker = eye2_;
elseif exist('joy_','var'), tracker = joy_; showcursor(true);
elseif exist('joy2_','var'), tracker = joy2_; showcursor2(true);
else, error('This demo requires eye or joystick input. Please set it up or turn on the simulation mode.');
end

bhv_code(10,'Fixation',20,'Stimulus',100,'Reward');
%editable('fix_rad','reward', 'reward_interval','grid_min','grid_max','stim_size','stim_time')
fixation_point = 1;

rf = [-5 -5];
x_pert = (-2.25:0.5:2.25)';
y_pert = (-2.25:0.5:2.25)';

prior_delay = 500;
stim_time = 100;
reward = 60;

x_suffle = x_pert(randperm(length(x_pert)));
y_suffle = y_pert(randperm(length(y_pert)));

x = x_suffle + rf(1);
y = y_suffle+rf(2);
box_pos = [x y];
time = ones(length(x_pert), 1)*stim_time;

bhv_variable('rf', rf)
bhv_variable('box_pos', box_pos);




fix = SingleTarget(eye_);
fix.Target = fixation_point;   
fix.Threshold = 1.5;
wth = WaitThenHold(fix);
wth.WaitTime = 5000;
wth.HoldTime = prior_delay;
scene0 = create_scene(wth);


box = BoxGraphic(wth);
box.EdgeColor = [0 0 0];
box.FaceColor = [1 1 1];
box.Size = [0.5 0.5];
box.Position = rf;



ct = CurveTracer(null_);
ct.Target = box;   % TaskObject#1
ct.List = [x y time];
ct.DurationUnit = 'msec';
scene1 = create_scene(ct, ct.Target);


error_type = 0;
run_scene(scene0,10);
if wth.Success 
    goodmonkey(reward, 'eventmarker', 100);
    run_scene(scene1,20);
    if ~ct.Success
        error_type = 3;  % fix break
    else
        goodmonkey(reward, 'eventmarker', 100);% Task fully completed
    end
else
    error_type = 4;  % no fixation
end


idle(0); % clear screen
trialerror(error_type);
if error_type == 0
    set_iti(100)
else
    set_iti(1000)
end


The code does not work even for the first trial, due to an error. See the parts rewritten in red again. I guess you do not see the dots, because you are presenting black dots on the black background. Start from a small, working example and expand it gradually.

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.