MATLAB Answers

0

Presenting 48 images in 4 conditions where each image is presented only once?

Robert Newman さんによって質問されました 2019 年 5 月 16 日
最新アクティビティ Rik
さんによって コメントされました 2019 年 5 月 21 日
Hi all,
New to programming and this problem has been wracking my brain for a few days now. Tried to figure it out myself to get the satisfaction but I need some help.
I have two folders with twenty four images each. The first folder contains 24 emotional images, and the second folder contains 24 non-emotional images. I want to present these images in four different conditions. They are as follows:
1 = emotional image on the left, non-emotional on the right
2 = non-emotional image on the left, emotional image on the right
3 = emotional images on both the left and right sides of the screen
4 = non-emotional images on both the left and right sides of the screen
Like I said, I want to present it so that each image is used once and only once. So far my code looks something like this:
%Defines the first column of a matrix that will be used to determine the
%presentation condition (e.g. emotional left - non emotional right). The
%first column consists of random numbers from 0-1 which will be sorted to
%determine the presentation condition. length(concRandPermutations) = 24
colOnePresCond = 0 + (1-0).*rand((length(concRandPermutations)),1);
%Defines the second column of the matrix. This will need to be manually
%edited. There are four conditions so there should be n numbers each from
%one to four where n is the number of trials (e.g. for 24 trials there
%would be 6 1s, and 6 2s, etc.
colTwoPresCond = [1;1;1;1;1;1;2;2;2;2;2;2;3;3;3;3;3;3;4;4;4;4;4;4];
%Creates the third and fourth columns, which is a random vector consisting of numbers 1-24. The third column represents the left side of the screen and the fourth column the right side. We will use these columns to call the corresponding image number in the emotional/non-emotional image directories.
colThreePresCond = randperm(24);
colThreePresCond = colThreePresCond';
colFourPresCond = randperm(24);
colFourPresCond = colFourPresCond';
%Creates the matrix that will be used to determine presentation conditions.
presCondUnsorted = [colOnePresCond,colTwoPresCond,colThreePresCond,colFourPresCond];
%Sorts by the first column of the previous matrix to create the
%presentation condition matrix.
presCond = sortrows(presCondUnsorted,1);
%Checks to make sure the same images will not be presented twice in the same trial
for b = 1:length(presCond)
if presCond(b,3) == presCond(b,4)
colThreePresCond = randperm(24);
colThreePresCond = colThreePresCond';
colFourPresCond = randperm(24);
colFourPresCond = colFourPresCond';
presCondUnsorted = [colOnePresCond,colTwoPresCond,colThreePresCond,colFourPresCond];
presCond = sortrows(presCondUnsorted,1);
b = 1;
%Checks to see if the loop ran
didThisLoopRun = 1;
end
end
----
%Example of code for calling the images in condition 1 where the emotional image is presented to the left side and the non-emotional is presented to the right side
if presCond(a,2) == 1
nonEmoImageMatrixLoc = presCond(a,3);
emoImageMatrixLoc = presCond(a,4);
loadLeftImage = imread(nonEmoDirectory(nonEmoImageMatrixLoc).name);
loadRightImage = imread(emoDirectory(emoImageMatrixLoc).name);
%Where both images are emotional
emoImageMatrixLocTwo = presCond(a,3);
emoImageMatrixLoc = presCond(a,4);
loadLeftImage = imread(emoDirectory(emoImageMatrixLocTwo).name);
loadRightImage = imread(emoDirectory(emoImageMatrixLoc).name);
Thanks in advance for your help!

  0 件のコメント

サインイン to comment.

1 件の回答

Rik
回答者: Rik
2019 年 5 月 16 日

Do you mean something like this?
%generate some empty structs for testing
%(replace by appropriate calls to the dir function)
EmoDirectory=struct;EmoDirectory(24).name='foo';
nonEmoDirectory=struct;nonEmoDirectory(24).name='bar';
if rem(numel(EmoDirectory),4)~=0
error('only works for multiples of 4')
end
%array containing display type
colTwoPresCond=repmat(1:4,numel(EmoDirectory)/4,1);
%randomize:
colTwoPresCond=colTwoPresCond(randperm(numel(colTwoPresCond)));
%convert the structs to cell arrays with file names
EmoDirectory={EmoDirectory(:).name};
nonEmoDirectory={nonEmoDirectory(:).name};
%randomize the list of filenames
EmoDirectory=EmoDirectory(randperm(numel(EmoDirectory)));
nonEmoDirectory=nonEmoDirectory(randperm(numel(nonEmoDirectory)));
%create a struct to hold the counters
count=struct;count.emo=0;count.non=0;
% 1 = emotional image on the left, non-emotional on the right
% 2 = non-emotional image on the left, emotional image on the right
% 3 = emotional images on both the left and right sides of the screen
% 4 = non-emotional images on both the left and right sides of the screen
for n=1:numel(colTwoPresCond)
switch colTwoPresCond(n)
case 1
count.emo=count.emo+1;
left=EmoDirectory{count.emo};
count.non=count.non+1;
right=nonEmoDirectory{count.non};
case 2
count.non=count.non+1;
left=nonEmoDirectory{count.non};
count.emo=count.emo+1;
right=EmoDirectory{count.emo};
case 3
count.emo=count.emo+1;
left=EmoDirectory{count.emo};
count.emo=count.emo+1;
right=EmoDirectory{count.emo};
case 4
count.non=count.non+1;
left=nonEmoDirectory{count.non};
count.non=count.non+1;
right=nonEmoDirectory{count.non};
end
%now do something useful with left and right
end

  1 件のコメント

Rik
2019 年 5 月 21 日
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.

サインイン to comment.



Translated by