How to randomise the order of only some images in a array
3 views (last 30 days)
Show older comments
Hi all,
I've got a folder of images (total 34 images) and I would like to randomise the order of the first 31 images only (images 32-34 would always be at the end).
So far I've called the images from a directory:
folderPath = '/Images/'; % set the dir for where you are keeping the images
getImage = dir(fullfile(folderPath, '*.jpg')); %gets a list of names for all the jpg files in the folder
choseImage = 1:length(getImage);% how many images do we have?
Here is where I'm trying to shuffle the first 31 images in 'choseImage'. This is what I've got but it isn't working...
ImShuffle = 1:31;
number = size(choseImage,1);
for k = ImShuffle
choseImage(:,k) = choseImage(randperm(number),k);
end
I want to shuffle the first 31 images so each time you run the script, 'standard' is a different image:
standard = choseImage(1);
oddballs = choseImage(2:31);
oddballs = oddballs(randperm(length(oddballs)));
male = choseImage(32:34);
When I don't try to shuffle the first 31 images the code works perfectly so I know I'm going wrong somewhere there. Any help would be amazing!
I'm also using psychtoolbox.
0 Comments
Accepted Answer
Jan
on 25 May 2021
choseImage is a vector, but here you access it as matrix with 2 indices:
choseImage(:,k) = choseImage(randperm(number),k);
To shuffle the first 31 elements:
choseImage = 1:length(getImage);
choseImage(1:31) = randperm(31);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!