How to present many images repeatedly and randomly? Problem Function
Afficher commentaires plus anciens
Hi all,
Matlab is still a new language to me and I would like to present 360 experimental trials based on 40 images (I want those images to be repeated and it should be presented randomly). I created the following Function but none of the parts works correctly :( Anybody to help?
% X
%This function is created to test the EGI system. Faces will be presented, half
%will be inverted.
function X
Screen('Preference', 'SkipSyncTests', 1)
%Open the screen
[wPtr,rect]=Screen('OpenWindow',max(Screen('Screens')),[0 0 600 600]);
xCenter=rect(3)/2;
yCenter=rect(4)/2;
imgPath = 'C:/Users/X/Desktop/MatlabTutorial/EGItest';
imgType = '*.jpeg';
images = dir(fullfile(['C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg']));
%Create textures
for n=1:20
images{n}=imread(sprintf('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg'));
end
imageData=imread('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg');
imageTexture=Screen('MakeTexture', wPtr,imageData);
%Get size of image (all images the same size in this example)
%imageHeight
%imageWidth
%colorChannels
[imageHeight, imageWidth,colorChannels]=size(imageData);
%Set up left and right picture locations
gap=100; %distance of pics from center
leftRect=[xCenter-gap-imageWidth, yCenter-imageHeight/2, xCenter+imageHeight/2];
rightRect=[xCenter+gap, yCenter-imageHeight/2, xCenter+gap+imageWidth, yCenter+imageHeight/2];
%set up some vectors with our options
allFiles=dir('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg');
allNames={allFiles.jpeg};
textures=[imageTexture];
textureNames={'allFiles'};
rects={leftRect, rightRect};
rectNames={'left', 'right'};
%loop for 200 trials
for trial=1:200
file_name=dir(strcat('C:/Users/X/Desktop/MatlabTutorial/EGItest', '*.jpeg'));
im=imread(strcat('C:/Users/X/Desktop/MatlabTutorial/EGItest','*.jpeg'));
imtool(im);
repelem(v,3);
end
%pick a random number 1 or 2
randTextureNum=randi(2);
%now use that number tp pick a texture
ourTexture=textures(randTextureNum);
%draw the pie
%windowPtr=wPtr
Screen('DrawTexture', wPtr, ourTexture,[], ourRect);
stimTime=Screen('Flip', wPtr);
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!