Why is my code not doing permutation?
显示 更早的评论
I am completely new to MATLAB, so I am going to use very lay terminology. I am not actually even sure if my question is correctly phrased.
I am trying to do a 2x2 mixed design. Factor 1 = direction which grating is pointing gratingleft.jpg OR gratingright.jpg Factor 2 = location on screen where grating is displayed [300 300 600 600] OR [100 300 600 600]
Thus I have made 4 if statements (if, elseif, elseif, else) that SHOULD display the following combinations randomly permutated. gratingleft.jpg [300 300 600 600] gratingleft.jpg [100 300 600 600] gratingright.jpg [300 300 600 600] gratingright.jpg [100 300 600 600]
But the experiment only displays ONE of them (currently, gratingright.jpg [100 300 600 600]. It ignores the others. I change grating left/right by an input earlier in the script (Current_Condition 1 OR 2) and the location should change using a vector of random numbers. This is all explained in detail in the code. %-------------------------------SPECIFICATIONS---------------------------------------------------- Number_Locations = 2; Number_Trials = 10;
standard_test = [1 1; 1 2; 1 3; 1 4; 1 5; 1 6; 1 7; 1 8; 1 9; 1 10; 2 1; 2 2; 2 3; 2 4; 2 5; 2 6; 2 7; 2 8; 2 9; 2 10]; % First I set up a 10x2 matrix standard_test(:,3) = randperm(length(standard_test)); % A third column of randomly ordered numbers from one up to % the total number of trials is added standard_test = sortrows(standard_test,3); % I use the randomly ordered numbers to shuffle the numbers in the "standard_test" matrix Standard_Order = standard_test(:,1); % And then pull out the first column for a vector of standard conditions % Standard_Order is now a 20x1 column vector of random 2's and 1's.
%--------------------------MAIN EXPERIMENT-------------------------------- %First, I want to create a gray (I have specified gray as "bgcolour" in the earlier script) screen here, which displays the opening instructions to the participant. The code below does this. win = Screen('OpenWindow',0, bgcolour, [100 100 1800 1000]); Screen('FillRect', win, bgcolour); Screen('TextSize',win, 20); Screen('TextFont',win,'Times New Roman'); Screen('TextStyle', win, 1); Screen('DrawText', win,'Hi! Thankyou for taking part in this experiment', 100, 200, textcolour); Screen('DrawText', win,'You will now be shown a series of gratings, appearing either to the left or right', 100, 300, textcolour); Screen ('DrawText', win, 'side of the screen. You need to determine the direction which the lines in the outer', 100, 400, textcolour); Screen ('DrawText', win, 'ring are pointing using the left or right arrow keys on your mousepad', 100, 500, textcolour); Screen ('DrawText', win, 'when you are ready, press the space bar to begin', 100, 600, textcolour); Screen(win,'Flip'); respToBeMade = true; %I want participants to press the 'spacebar' to move on while respToBeMade [keyIsDown,secs,pressedKeys] = KbCheck; if pressedKeys (spaceBar) %if spacebar is pressed, move on for i = 1:10 %now, I want the experiment to loop 10 times. Standard = Standard_Order (i); %As my experiment is a 2x2 mixed-factor design, 1 %factor (Current_Condition) I specify using an input function closer to the %top of the script (1 or 2). The other condition I want to specify by the %script entering the vector "Standard_Order" once per loop. "Standard_Order %is a column vector of random 1 and 2s(20:1). So basically for every i, I %want the script to re-enter "Standard_Order" and look at the value on a %new row of the column vector. Then, it will (hopefully) run a slightly %different script depending on the Current_Condition (which I set) and the %Standard. The variations can be seem in the if-statements below. if Current_Condition == 1 && Standard == 1,(i); Screen ('DrawText', win, 'Ready? Remember to look at the directions of the outer grating', 100, 400, textcolour); Screen(win,'Flip'); %displays the above text WaitSecs (3); %displays above text for 3 seconds ima=imread(Gratingleft, 'jpg'); %reads in the image (NOTE GRATING LEFT.JPG) imagetexture = Screen('MakeTexture', win, ima); %makes a texture Screen('DrawTexture',win,imagetexture,[],[300 300 600 600]); %displays the image on the texture (NOTE %TEXTURE PLACEMENT Screen(win,'Flip'); WaitSecs (2); secs0=GetSecs; %begins counting seconds Screen('DrawText', win,'Which direction was the outer grating pointing?', 100, 400, textcolour); Screen('DrawText', win,'Press the left arrow for left, and the right arrow for right', 100, 500, textcolour); Screen(win,'Flip'); %displays text respToBeMade = true; %requires a reponse while respToBeMade [keyIsDown,secs,pressedKeys] = KbCheck; if pressedKeys (escapeKey) ShowCursor; sca; return elseif pressedKeys (leftarrow); keyResp = 1; respToBeMade = false; elseif pressedKeys (rightarrow); keyResp = 2; respToBeMade = false; RT=secs-secs0; % Get reaction time fprintf(File2,'%s','\n', keyResp); fprintf(File2,'%4.2f','\n',RT); end end elseif Current_Condition == 1 && Standard == 2,(i); %THIS IS ANOTHER CONDITION, STANDARD IS NOW = 2 Screen ('DrawText', win, 'Ready? Remember to look at the directions of the outer grating', 100, 400, textcolour); Screen(win,'Flip'); WaitSecs (3); ima=imread(Gratingright, 'jpg'); %NOTE GRATINGRIGHT.JPG imagetexture = Screen('MakeTexture', win, ima); Screen('DrawTexture',win,imagetexture,[],[100 300 600 600]); %NOTE TEXTURE PLACEMENT Screen(win,'Flip'); WaitSecs (2); secs0=GetSecs; Screen('DrawText', win,'Which direction was the outer grating pointing?', 100, 400, textcolour); Screen('DrawText', win,'Press the left arrow for left, and the right arrow for right', 100, 500, textcolour); Screen(win,'Flip'); respToBeMade = true; while respToBeMade [keyIsDown,secs,pressedKeys] = KbCheck; if pressedKeys (escapeKey) ShowCursor; sca; return elseif pressedKeys (leftarrow); keyResp = 1; respToBeMade = false; elseif pressedKeys (rightarrow); keyResp = 2; respToBeMade = false; RT=secs-secs0; % Get reaction time fprintf(File2,'%s','\n', keyResp); fprintf(File2,'%4.2f','\n',RT); end end elseif Current_Condition == 2 && Standard == 1,(i); %YET ANOTHER CONDITION, SEE HOW CURRENT CONDITION HAS BEEN CHANGED TO '2' AND STANDARD IS BACK TO '1' Screen ('DrawText', win, 'Ready? Remember to look at the directions of the outer grating', 100, 400, textcolour); Screen(win,'Flip'); WaitSecs (3); ima=imread(Gratingleft, 'jpg'); %NOTE GRATING LEFT.JPG imagetexture = Screen('MakeTexture', win, ima); Screen('DrawTexture',win,imagetexture,[],[100 300 600 600]); %NOTE TEXTURE PLACEMENT Screen(win,'Flip'); WaitSecs (2); secs0=GetSecs; Screen('DrawText', win,'Which direction was the outer grating pointing?', 100, 400, textcolour); Screen('DrawText', win,'Press the left arrow for left, and the right arrow for right', 100, 500, textcolour); Screen(win,'Flip'); respToBeMade = true; while respToBeMade [keyIsDown,secs,pressedKeys] = KbCheck; if pressedKeys (escapeKey) ShowCursor; sca; return elseif pressedKeys (leftarrow); keyResp = 1; respToBeMade = false; elseif pressedKeys (rightarrow); keyResp = 2; respToBeMade = false; RT=secs-secs0; % Get reaction time fprintf(File2,'%s','\n', keyResp); fprintf(File2,'%4.2f','\n',RT); end end else %THIS IS THE LAST POSSIBLE CONDITION (AS IT IS 'ELSE' I DONT SPECIFY BUT IT SHOULD MEAN %CURRENT_CONDITION = 2 && STANDARD ==2; Screen ('DrawText', win, 'Ready? Remember to look at the directions of the outer grating', 100, 400, textcolour); Screen(win,'Flip'); WaitSecs (3); ima=imread(Gratingright, 'jpg'); %NOTE GRATINGRIGHT.JPG imagetexture = Screen('MakeTexture', win, ima); Screen('DrawTexture',win,imagetexture,[],[100 300 600 600]); %NOTE TEXTURE PLACEMENT Screen(win,'Flip'); WaitSecs (2); secs0=GetSecs; Screen('DrawText', win,'Which direction was the outer grating pointing?', 100, 400, textcolour); Screen('DrawText', win,'Press the left arrow for left, and the right arrow for right', 100, 500, textcolour); Screen(win,'Flip'); respToBeMade = true; while respToBeMade [keyIsDown,secs,pressedKeys] = KbCheck; if pressedKeys (escapeKey) ShowCursor; sca; return elseif pressedKeys (leftarrow); keyResp = 1; respToBeMade = false; elseif pressedKeys (rightarrow); keyResp = 2; respToBeMade = false; RT=secs-secs0; % Get reaction time fprintf(File2,'%s','\n', keyResp); fprintf(File2,'%4.2f','\n',RT); end end end end end end ShowCursor; sca;
I hope my notes make some sort of sense. Please help!
1 个评论
David Barry
2016-12-11
Please format your code in to a readable state then we might be able to help.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 App Building 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!