-
Notifications
You must be signed in to change notification settings - Fork 2
/
runGetStim.m
137 lines (100 loc) · 4.63 KB
/
runGetStim.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
%% Tidy and get working directory
clear all
studyDir = pwd;
fprintf('The current directory is %s\n',studyDir)
dirCheck = input('Is this the correct study directory (y/n)? ', 's');
if dirCheck ~= 'y'
studyDir = input('Please specify the full path to the correct study directory: ', 's');
end
%% Select stimuli and populate folders
categories = {'Chocolate' 'Cookies' 'Donuts' 'French Fries' 'Ice Cream' 'Pasta' 'Pizza'};
nCategories = length(categories);
mostCravedTrue = 'n';
leastCravedTrue = 'n';
while mostCravedTrue ~= 'y'
fprintf('\n\nWhich category of food do you crave the MOST? \n');
fprintf('(Where "crave" means that you want it, like it, and would eat it if it were in front of you, even if you were full.)\n\n');
for i = 1:nCategories
fprintf('%2.0f - %s\n',i,categories{i});
end
mostCraved = input('\nPlease select a category: ');
fprintf('You selected %s. ', categories{mostCraved});
mostCravedTrue = input('Is that correct? (y/n): ','s');
end
fprintf('\n\nGreat, let''s move on...\n\n');
while leastCravedTrue ~= 'y'
fprintf('\n\nWhich category of food do you crave the LEAST? \n');
fprintf('(Where "crave" means that you want it, like it, and would eat it if it were in front of you, even if you were full.)\n\n');
for i = 1:nCategories
fprintf('%2.0f - %s\n',i,categories{i});
end
leastCraved = input('\nPlease select a category: ');
fprintf('You selected %s. ', categories{leastCraved});
leastCravedTrue = input('Is that correct? (y/n): ','s');
end
fprintf('\n\nExcellent, thank you.\n\n\n');
cd(studyDir) %Make sure this works
craveDir = strcat('Crave_',num2str(mostCraved)); % Where are the craved food files (labeled as "Crave01.jpg", etc.)
noCraveDir = strcat('NoCrave_',num2str(leastCraved)); % Where are the non-craved food files (labeled as "NoCrave01.jpg", etc.)
% Go into the Resources folder and remove all of the existing "crave##.jpg"
% and "nocrave##.jpg" images
cd('Resources')
delete *crave*.jpg
cd('..')
if rand>0.5 % Coin flip--half of the time swap pics so not always using the same images for reappraise/view
% Go into the crave directory, list the files, and figure out where
% everything lives
cd(craveDir)
craveFiles = dir('crave*.jpg');
prefixInd = strfind(craveFiles(1).name,'.');
prefix = craveFiles(1).name(1:prefixInd-3);
% Loop through each file...
for j = 1:length(craveFiles)
oldFileN = str2double(craveFiles(j).name(prefixInd-2:prefixInd-1)); % Original file number
% If it is odd, add one; if even, subtract one
if mod(j,2) % odds
newFileN = oldFileN+1;
else %evens
newFileN = oldFileN-1;
end
newFile = strcat(prefix,num2str(newFileN,'%02.0f'),'.jpg'); % The name of the new file
[success,msg] = copyfile(craveFiles(j).name,strcat('../Resources/',newFile),'f'); % Copy the new file to resources
if ~success
fprintf('Error: %s on crave file %2.0f\n',msg,j);
end
WaitSecs(.01);
end
cd('../') % Back up to the main task directory
% Go into the no-crave directory, list the files, and figure out where
% everything lives
cd(noCraveDir);
noCraveFiles = dir('nocrave*.jpg');
prefixInd = strfind(noCraveFiles(1).name,'.');
prefix = noCraveFiles(1).name(1:prefixInd-3);
% Loop through each file...
for j = 1:length(noCraveFiles)
oldFileN = str2double(noCraveFiles(j).name(prefixInd-2:prefixInd-1)); % Original file number
% If it is odd, add one; if even, subtract one
if mod(j,2) % odds
newFileN = oldFileN+1;
else %evens
newFileN = oldFileN-1;
end
newFile = strcat(prefix,num2str(newFileN,'%02.0f'),'.jpg'); % The name of the new file
[success,msg] = copyfile(noCraveFiles(j).name,strcat('../','Resources/',newFile),'f'); % Copy the new file to resources
if ~success
fprintf('Error: %s on nocrave file %2.0f\n',msg,j);
end
WaitSecs(.01);
end
cd('../'); % Back up to the main task directory
else % Coin flip--other half of the time just copy the files into the Resources directory as the are
[success,msg] = copyfile(strcat(craveDir,'/*'),'Resources','f');
if ~success
fprintf('Error: %s on crave file.\n',msg);
end
[success,msg] = copyfile(strcat(noCraveDir,'/*'),'Resources','f');
if ~success
fprintf('Error: %s on nocrave file.\n',msg);
end
end