help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

octave mistake


From: tecla mohr
Subject: octave mistake
Date: Mon, 18 Jun 2018 15:03:01 +0200

Dear all, I have a problem to run my script. It does not open the screen of my task. 
here below you can find my code. I will appreciate if someone can help me. I'm new user with octave so I don't know how it works, I have always used Matlab.

this is my entire code:

function results=BlueSquareCentered(name, nbTrials, rectSize, testType,window1, positiveSound, negativeSound)

% test types:
% type 1: only one click per test allowed and RT value is reaction time
% test 2: test stays on until correct click is performed and RT is total
% numbre of clicks per test

black = [0 0 0];
blue = [0 255 0];
white = [255 255 255];
esc = KbName('ESCAPE');
RestrictKeysForKbCheck(esc);
results = table;
dotSizePix=75;
dotColor=[150 25 75];

% Get the size of the on screen window
pixelSize=Screen('PixelSize', window1)
[screenXpixels, screenYpixels] = Screen('WindowSize', window1);
screenRect=[0 0 screenXpixels screenYpixels];
[x,y]=RectCenter(screenRect);

% create a rectangle middle stimulus of 350 pixels
baseRect = [0 0 rectSize rectSize]; % also specified individually for each test chimp

% center it in the middle of the screen
centeredRect = CenterRectOnPointd(baseRect, x, y);

if testType==1
   
for j=1:nbTrials

% have a short blank screen between trials
Screen(window1, 'FillRect', black);
Screen('Flip', window1);
WaitSecs(3);

Screen(window1, 'FillRect', white);
Screen('FillRect', window1, blue, centeredRect);
startTime=Screen('Flip', window1);

while 1

[~,~,keyCode] = KbCheck;
      if keyCode(esc)
%          close all
         sca;
         return;
      end
      
[mx,my,buttons]=GetMouse(window1); %to get location
inside=IsInRect(mx,my,centeredRect);% check whether click was inside the figure
rt=GetSecs-startTime;

% set reward for correct click, neg sound for incorrect press
    if any(buttons)>0 && inside==0
        sound(negativeSound, 44100);
        Screen('FillRect', window1, blue, centeredRect);
        Screen('DrawDots', window1, [mx my], dotSizePix, dotColor, [], 3);
        Screen('Flip', window1);
        WaitSecs(0.5);
        break
    elseif any(buttons)>0 && inside==1
        sound(positiveSound, 44100);
        disp('reward');
        Screen('FillRect', window1, blue, centeredRect);
        Screen('DrawDots', window1, [mx my], dotSizePix, dotColor, [], 3);
        Screen('Flip', window1);
        WaitSecs(0.5);
        break
    end
    WaitSecs(0.01);
    
end


res= table(datetime('now'),name, j, rectSize, inside, rt, "BSC");
results = [results; res];

end

elseif testType==2
    
for j=1:nbTrials

rt=0;

% have a short blank screen between trials
Screen(window1, 'FillRect', black);
Screen('Flip', window1);
WaitSecs(3);

Screen(window1, 'FillRect', white);
Screen('FillRect', window1, blue, centeredRect);
Screen('Flip', window1);
WaitSecs(0.01);

 while 1
        
    [~,~,buttons] = GetMouse(window1);
     % If already down, wait for release...
    while any(buttons)
      [~,~,keyCode] = KbCheck;
      if keyCode(esc)
%          close all
         sca;
         return;
      end
        [~,~,buttons] = GetMouse(window1);
        WaitSecs(0.01);
    end
  
        % Wait for a press or timeout:
    while ~any(buttons)
      [~,~,keyCode] = KbCheck;
      if keyCode(esc)
%          close all
         sca;
         return;
      end
        [mx,my,buttons] = GetMouse(window1);
        inside=IsInRect(mx,my,centeredRect);
        
        WaitSecs(0.01);    
    end
            % Mouse click
    if inside==1 && any(buttons)
        sound(positiveSound, 44100);
        Screen('FillRect', window1, blue, centeredRect);
        Screen('DrawDots', window1, [mx my], dotSizePix, dotColor, [], 3);
        Screen('Flip', window1);
        disp('reward');
        rt=rt+1;
        break
    elseif inside==0 && any(buttons)
        sound(negativeSound, 44100);
        Screen('FillRect', window1, blue, centeredRect);
        Screen('DrawDots', window1, [mx my], dotSizePix, dotColor, [], 3);
        Screen('Flip', window1);
        rt=rt+1;
    end
    WaitSecs(0.01);
    
    while any(buttons)
      [~,~,keyCode] = KbCheck;
      if keyCode(esc)
%          close all
         sca;
         return;
      end
        [~,~,buttons] = GetMouse(window1);
        WaitSecs(0.01);
    end
    WaitSecs(0.01);

    
 end

res= table(datetime('now'),name, j, rectSize, inside, rt, "BSC");
results = [results; res];

end 
end
results.Properties.VariableNames = {'datetime', 'ID', 'test', 'rectpixels', 'correct', 'RT', 'task'};
end

thank you for your time and your help
Tecla

reply via email to

[Prev in Thread] Current Thread [Next in Thread]