MATLAB: Is there a way to incorporate scripts into a for loop, instead of images as stimuli for an experiment

incorporating external scriptspsychtoolboxrandomization of trialsvisual perception experiment

I am working on creating a visual perception experiment, using PsychToolbox. The experiment will consist of 160 trials. In each trial, the subject is presented with a sequence of images (an object composed of simple shapes, followed by a masking image, followed by another simple-shape-object). In order to present the images in the proper sequence within each trial, I believe it will be easiest to make a separate script for each trial. Then, I want to use a for loop to randomly present each trial. Is this possible?
Here is an example code for one of the trials:
image1 = imread('ccc.s.jpg');
image2 = imread('ccc.dc.jpg');
mask = imread('mask.jpg');
Image1=Screen('MakeTexture', expWin, image1);
Image2=Screen('MakeTexture', expWin, image2);
Mask = Screen('MakeTexture', expWin, mask);
Screen('DrawTexture', expWin, Image1);
Screen('Flip', expWin);
WaitSecs(0.300);
Screen('DrawTexture', expWin, Mask);
Screen('Flip', expWin);
WaitSecs(0.500);
Screen('DrawTexture', expWin, Image2);
Screen('Flip', expWin);
WaitSecs(0.300);
end
I will create 160 of these, 1 script for each trial. How do I use a for loop to randomly present the 160 trials, which will be created in external scripts?
And this is a portion of the experiment where the for loop will need to be incorporated:
% Open Screen
[expWin,rect]=Screen('OpenWindow',0);
% alternative: replace the above with smaller window for testing
% [expWin,rect]=Screen('OpenWindow',screenNumber,[],[10 20 1200 700]);
% Get rid of cursor.
HideCursor;
% Choose a text size
Screen('TextSize', expWin, 24);
% Display Instructions Text
DrawFormattedText(expWin, Instructions, 'center', 'center');
Screen('Flip', expWin);
%Display Practice Trials Next Text
DrawFormattedText(expWin, PracticeTrialsNext, 'center', 'center');
KbWait([], 3);
Screen('Flip', expWin);
***% Practice Trial loop goes here***
%Display Next Trial Text (This needs to somehow be incorporated into the
%loops for practice trials and experimental trials)
DrawFormattedText(expWin, NextTrial, 'center', 'center');
Screen('Flip', expWin);
%Display Experimental Trials Next Text
DrawFormattedText(expWin, ExperimentalTrialsNext, 'center', 'center');
KbWait([], 3);
Screen('Flip', expWin);
***% Experimental Trial loop goes here***
%Display End Text
DrawFormattedText(expWin, End, 'center', 'center');
KbWait([], 3);
Screen('Flip', expWin);
Screen('CloseAll')
ShowCursor;
fclose('all');
I also have a string of text that needs to follow each trial. Is there a simple way to incorporate this within the for loop as well?
Thanks in advance.

Best Answer

files_to_run = {'do_this', 'do_that', 'do_the_other', 'but_not_with_sizzors'};
thisfile = files_to_run{ 1 + floor( rand * length(files_to_run) ) };
run(thisfile)
Related Question