octave mistake

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

octave mistake

tecla
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 | Threaded
Open this post in threaded view
|

Re: octave mistake

Przemek Klosowski-7
On 06/18/2018 09:03 AM, tecla mohr wrote:
> 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.
>
Your code implements a procedure BlueSquareCentered, so you need to call
it. I didn't try to guess what parameters you need to give it, but I see
that you use Matlab functions like KbName, which is apparently part of
psychotoolbox. YOu need to figure out what pieces you're using and check
if they run under Octave.

Could you please try to trim your code to provide a short (<10 line)
example of what you want to accomplish and explain why the result in
Octave is not what you expect.

Also, please reformat your code for consistent indentation (I ran it
through Emacs octave mode indenting below, which may be a good start)


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