Experiment with a random presentation of images from a folder

7 次查看(过去 30 天)
Hi everyone, I'm new to matlab. I am trying to create a script for my experiment. The script should consist in the presentation on the screen of 40 images showing emotional faces (with 3 different emotions: neutral, happy, angry) from a folder called "images.experiment". These images must be presented randomly without repeating themselves in a loop which is repeated 3 times. After each image I should make an assessment of the intensity ("how emotional is the stimulus you see?") of the emotion in the image on a Likert scale from 1 to 9. Finally I have to save every answer (according to the condition/image) of each subject on an excel document. Can someone help me? I am using Psychtoolbox on Window. Thanks everyone in advance.
  4 个评论
Walter Roberson
Walter Roberson 2022-10-16
randperm(40) three times to get the order of presentation. The rest about showing an image at a particular location for a particular time is really psychtoolbox functions not MATLAB. Functions to get input with timing is also psychtoolbox

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2022-10-16
移动:Walter Roberson 2022-10-16
http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F shows how you can read a series of files. assign them into a cell array. Then
numfiles = numel(YourCellArray);
order_to_show = [randperm(numfiles), randperm(numfiles), randperm(numfiles)];
Now do whatever psychtoolbox requires you to do in order to set up the screen. Then you would do something similar to
for K = 1 : numel(order_to_show)
this_image = YourCellArray{order_to_show(K)};
do whatever psychtoolbox needs to present the fixation point for the given time
do whatever psychtoolbox needs to present this_image for the given time
do whatever psychtoolbox needs to present the mask for the given time
do whatever psychtoolbox needs to retrieve the user input
responses(K) = user response
end
results = table(order_to_show(:), responses(:), 'VariableNames', {'ImageNumber', 'Response'});
writetable(results, 'FileNameToWriteTo.xlsx');
You might modify the results table slightly if you wanted to write in the image name instead of the image number (index), something like
results = table(ImageNames(order_to_show(:)), responses(:), 'VariableNames', {'ImageName', 'Response'});
  3 个评论
Walter Roberson
Walter Roberson 2022-10-16
All the details about presenting for a given time or fetching user input, are using Psychtoolbox supplied functions. Psychtoolbox has its own support forum. The details are not really appropriate here since they are third-party functions not supplied as part of Mathworks products.
Clarissa
Clarissa 2022-10-17
try
Screen('Preference', 'SkipSyncTests', 1);
% Open window with default settings:
myWindow=Screen('OpenWindow', 0, 127);
% Specify the folder where the files live.
myFolder = 'C:\Users\clari\OneDrive\Desktop\MATLAB\im.prova';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.png'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
numfiles = numel(imageArray);
order_to_show = [randperm(numfiles), randperm(numfiles), randperm(numfiles)];
for K = 1 : numel(order_to_show)
this_image = imageArray(order_to_show(K));
texture(K)=Screen('MakeTexture',myWindow,this_image);
end
for K= 1:numel(order_to_show)
Screen('DrawTexture',myWindow,texture(K))
Screen('Flip',myWindow);
%wait
WaitSecs(0.2)
end
%close the screen
sca;
catch
%#ok<*CTCH>
% This "catch" section executes in case of an error in the "try"
% section []
% above. Importantly, it closes the onscreen window if it's open.
sca;
fclose('all');
psychrethrow(psychlasterror);
end
I'm tryng doing this but it doesn't work and when I run this, MATLAB crashes completely

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image display and manipulation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by