MatLab:我如何随机呈现图片?

问题描述 投票:0回答:1

我需要学习如何在MatLab中随机呈现一系列图片。这对于许多认知心理学实验至关重要。到目前为止,我可以展示这些照片。有人能告诉我如何修改我现有的代码来随机呈现图片吗?非常感谢初学者!

这是我目前的代码:

close all
clear all
sca
clc

%Finds screen and uses it
screens = Screen('Screens');
screenNumber = max(screens);

%Gather all pictures to be used. Tell comp where they are. Make them all variables
StimuliFolder='C:\Matlab Stuff\'; %tells us where to look for image
N=imread([StimuliFolder 'nadal.jpg']); %reads the image from the following location
K=imread([StimuliFolder 'nishikori.jpg']); %reads the image from the following location
F=imread([StimuliFolder 'fed.jpg']); %reads the image from the following location
J=imread([StimuliFolder 'Bistable_Jazz_Woman.jpg']);
H=imread([StimuliFolder 'Bistable_Horse_face.jpg']);
D=imread([StimuliFolder 'daliface.jpg']);


%Define and use color for screen background
white = WhiteIndex(screenNumber);

%Opens window
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, white);

%Create a welcome screen that has text
Screen('TextSize', window, 40);
Screen('Textfont', window, 'Papyrus');
Screen('TextStyle', window, 1);
Screen('DrawText', window, 'Down the rabbit hole we go..', 300, 250, [0, 0, 0]);
Screen('TextSize', window, 20);
Screen('DrawText', window, '< When ready press any key to continue >', 300, 550, [0, 130, 150]);
Screen('Flip', window);
KbStrokeWait; %Press any key to continue

% Make the Nadal image into a texture and present it
imageTexture = Screen('MakeTexture', window, N);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1);

%Make the Fed image into a texture and present it
imageTexture = Screen('MakeTexture', window, F);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1);

%Make the Nishikori image into a texture and present it
imageTexture = Screen('MakeTexture', window, K); %refer to list, curly bracket and number in list
Screen('DrawTexture', window, imageTexture, [],[], 0);
Screen('Flip', window);
WaitSecs(1)

%Make and present Bistable Jazz face
imageTexture = Screen('MakeTexture', window, J);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1)

%Make and present Bistable horse face
imageTexture = Screen('MakeTexture', window, H);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1)

%Make and present Dali painting
imageTexture = Screen('MakeTexture', window, D);
Screen('DrawTexture', window, imageTexture, [], [], 0);
Screen('Flip', window);
WaitSecs(1)

%Goodbye screen
Screen('TextSize', window, 40);
Screen('Textfont', window, 'Papyrus');
Screen('TextStyle', window, 1);
Screen('DrawText', window, '...and out the other end', 300, 250, [0, 0, 0]);
Screen('DrawText', window, '< Press any key to exit >', 300, 550, [0, 130, 150]);
Screen('Flip', window);
KbStrokeWait; %Press any key to escape

sca %Closes the final screen when done
image matlab random
1个回答
1
投票

如何添加类似的东西

files = {'nadal';'nishikori';'fed';'Bistable_Jazz_Woman';'Bistable_Horse_face';'daliface'};

而不是你对N,K,F等的定义?加上一个随机向量v和一个用于显示的循环:

v = randperm(length(files));
for pl = 1:length(files)
    N=imread([StimuliFolder files{v(pl)} '.jpg'])
    imageTexture = Screen('MakeTexture', window, N);
    Screen('DrawTexture', window, imageTexture, [], [], 0);
    Screen('Flip', window);
    WaitSecs(1);
end 

附:我不知道功能屏幕?

© www.soinside.com 2019 - 2024. All rights reserved.