Reputation: 3
I need to learn how to randomly present a series of pictures in MatLab. This is essential to a lot of experiments in cognitive psychology. So far I can just present the pics. Can someone tell me how to modify my existing code to present the pictures randomly? Many thanks from a beginner!
Here's my current code:
close all
clear all
sca
clc
%Finds screen and uses it
screens = Screen('Screens');
screenNumber = max(screens);
%Gather all pictures to be used. Tell comp where they are. Make them all variables
StimuliFolder='C:\Matlab Stuff\'; %tells us where to look for image
N=imread([StimuliFolder 'nadal.jpg']); %reads the image from the following location
K=imread([StimuliFolder 'nishikori.jpg']); %reads the image from the following location
F=imread([StimuliFolder 'fed.jpg']); %reads the image from the following location
J=imread([StimuliFolder 'Bistable_Jazz_Woman.jpg']);
H=imread([StimuliFolder 'Bistable_Horse_face.jpg']);
D=imread([StimuliFolder 'daliface.jpg']);
%Define and use color for screen background
white = WhiteIndex(screenNumber);
%Opens window
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, white);
%Create a welcome screen that has text
Screen('TextSize', window, 40);
Screen('Textfont', window, 'Papyrus');
Screen('TextStyle', window, 1);
Screen('DrawText', window, 'Down the rabbit hole we go..', 300, 250, [0, 0, 0]);
Screen('TextSize', window, 20);
Screen('DrawText', window, '< When ready press any key to continue >', 300, 550, [0, 130, 150]);
Screen('Flip', window);
KbStrokeWait; %Press any key to continue
% Make the Nadal image into a texture and present it
imageTexture = Screen('MakeTexture', window, N);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1);
%Make the Fed image into a texture and present it
imageTexture = Screen('MakeTexture', window, F);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1);
%Make the Nishikori image into a texture and present it
imageTexture = Screen('MakeTexture', window, K); %refer to list, curly bracket and number in list
Screen('DrawTexture', window, imageTexture, [],[], 0);
Screen('Flip', window);
WaitSecs(1)
%Make and present Bistable Jazz face
imageTexture = Screen('MakeTexture', window, J);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1)
%Make and present Bistable horse face
imageTexture = Screen('MakeTexture', window, H);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1)
%Make and present Dali painting
imageTexture = Screen('MakeTexture', window, D);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1)
%Goodbye screen
Screen('TextSize', window, 40);
Screen('Textfont', window, 'Papyrus');
Screen('TextStyle', window, 1);
Screen('DrawText', window, '...and out the other end', 300, 250, [0, 0, 0]);
Screen('DrawText', window, '< Press any key to exit >', 300, 550, [0, 130, 150]);
Screen('Flip', window);
KbStrokeWait; %Press any key to escape
sca %Closes the final screen when done
Upvotes: 0
Views: 1317
Reputation: 443
How about adding something like
files = {'nadal';'nishikori';'fed';'Bistable_Jazz_Woman';'Bistable_Horse_face';'daliface'};
in stead of your definition of N,K,F etc.? Plus a randomized vector v, and a single loop for displaying:
v = randperm(length(files));
for pl = 1:length(files)
N=imread([StimuliFolder files{v(pl)} '.jpg'])
imageTexture = Screen('MakeTexture', window, N);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1);
end
p.s. I don't know the function Screen?
Upvotes: 1