How can I pull a random image to display, from a folder of images using Psychtoolbox?
9 views (last 30 days)
I am trying to show an image, randomly selected from a folder of images. I'm using Psychtoolbox. How do I instruct it to pull an image randomly from the folder, to display on the screen? The images can be used more than once.
Orion on 4 Nov 2014
Edited: Orion on 4 Nov 2014
I don't know this toolbox (not sure a lot of people do).
but in a general way, with matlab, you can do something like
% get all images (here all *.jpg found in the current directory, but you can specify the format you want)
MyImages = dir(fullfile(pwd,'*.jpg'));
% generate a random number between 1 and the number of images
RandomNumber = randi([1 size(MyImages,1)]);
% get the corresponding name of the image
MyRandomImage = MyImages(RandomNumber).name;
% display the image