How to randomise the order of only some images in a array

1 回表示 (過去 30 日間)
Sam Curtis
Sam Curtis 2021 年 5 月 25 日
コメント済み: Sam Curtis 2021 年 5 月 25 日
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.

採用された回答

Jan
Jan 2021 年 5 月 25 日
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);
  1 件のコメント
Sam Curtis
Sam Curtis 2021 年 5 月 25 日
Oh I see where I went wrong, thanks so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by