Select a number of images randomly from an array and have a number equal to that list

5 vues (au cours des 30 derniers jours)
I have a code where I have an x amount of images (x=60) and want to select y (y=30 for ex.) of those for phase 1 (where we present images with Psychtoolbox)
In the phase 1, we wish to present images for the participant to memorize them. On phase 2, 10 of those images will be presented along with 5-10 new images, the participant will have to do a keypress for an old response and new response. (old response means they have seen those images in the first phase)
% phase 1: 30 images
% phase 2: 10 old images(from those 30 in phase 1) and 5-10 new images
allimages = dir('**/*.png'); % directory of our images
imgname = {allimages.name}; % puts image names into an array
imgnumber = length(imgname); % counts total number of images (60)
randomorder = [randperm(imgnumber)]; %randomize the 60 images numbers list
% images for phase 1
img_phase1 = randperm(imgnumber,30); % select 30 random images from those 60
% where my problem code is:
img_old = randperm(length(img_phase1), 10); % I want to select 10 images from those 30, but they have to be randomly selected on each trial.
The problem I have is that the img_old has just randomly selected numbers (from 1 to 30) and picked 10 of those. What I want is for 10 of those numbers to be FROM the list of 30 images (which is random, so it includes 30 different items of different numbered images). I want 10 of those to be the same to 10 of the 30 list.
How do I go about it?

Réponse acceptée

Image Analyst
Image Analyst le 30 Nov 2020
Try this:
img_phase1 = randperm(imgnumber,30); % select 30 random images from those 60
% Get 10 random indexes in the range 1-30.
indexes10 = randperm(length(img_phase1), 10); % I want to select 10 images from those 30, but they have to be randomly selected on each trial.
% Extract 10 indexes from the list of 30 that were pulled from the original 60.
% indexes will only have indexes that exist in img_phase1.
% For example if 49 was not one of the 30 chosen from the 60,
% then 49 will definitely not be one of the final 10 indexes.
indexes = img_phase1(indexes10);

Plus de réponses (0)

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by