Advertisement
limah

EA_loop

Feb 25th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.06 KB | None | 0 0
  1. function process_interval_loop
  2. % Velez Valence Processing v.01
  3. %
  4. % The script is intended to expedite the valence scoring of the EA_EEG
  5. % experiments for both targets and perceivers. It requires a computer with
  6. % MATLAB 7 installed.
  7. clc;
  8. clear all;
  9.  
  10. %% Initial input queries %%
  11. subID = input('Enter Subject ID (e.g. 201): ','s');
  12. intervals = input('Enter the amount of intervals: ');
  13. valence = input('Was the video watched positive or negative?: ','s');
  14. phase = input('Is this the target or perceiver phase?: ','s');
  15.  
  16. %% Open file for writing output
  17. outputFilename = sprintf('subject%s_%s_%s.txt',subID,phase,valence);
  18. fid = fopen(outputFilename,'w+');
  19. fprintf(fid,'IntervalNumber\tWeightedAvg\tPhase\tValence\tsubID\n'); % Write headers on text file
  20.  
  21. %% Record data and loop
  22. for i=1:intervals
  23. buttonPresses(i) = input('Enter the amount of button presses within the interval ');% Initial input queries
  24.  
  25. % No button presses
  26. if buttonPresses(i) == 0
  27. score = input('Enter the only score in the interval');
  28. int_avg = score;
  29. currentInt = num2str(i); % What stage of the loop are we in
  30. fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
  31.  
  32. % Begin if/else logic to process data into weighted means
  33. elseif buttonPresses(i) > 0 && buttonPresses(i) <= 1
  34. score1 = input('Enter the previous score: '); % Score before the first button press.
  35. score2 = input('Enter the current score: '); % Score of the first button press.
  36. time1 = input('Enter the response time: '); % Time that the first button press occured.
  37. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  38. score2_int = (fix(time1/2)*2 + 2) - time1; % Time that score2 is present in the interval.
  39. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  40. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  41. weightedMean1 = score1*perc_time1; % The weighted mean of the score before the first button press.
  42. weightedMean2 = score2*perc_time2; % The weighted mean of the score after the first button press.
  43.  
  44. %Display interval average
  45. int_avg = weightedMean1 + weightedMean2;
  46. currentInt = num2str(i); % What stage of the loop are we in
  47. fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
  48.  
  49. elseif buttonPresses(i) > 1 && buttonPresses(i) <=2
  50. %Initial input queries
  51. score1 = input('Enter the score preceding the first button press: '); % Score before the first button press.
  52. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured.
  53. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press.
  54. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred.
  55. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press.
  56.  
  57. %Time represented in the interval
  58. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  59. score2_int = time2 - time1; % Time that score2 is present in the interval.
  60. score3_int = (fix(time1/2)*2 + 2) - time2; % Time that score3 is present in the interval.
  61. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  62. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  63. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval.
  64.  
  65. %Weighted means of each score by space in the interval.
  66. weightedMean1 = score1*perc_time1; % The weighted mean of the first score.
  67. weightedMean2 = score2*perc_time2; % The weighted mean of the second score.
  68. weightedMean3 = score3*perc_time3; % The weighted mean of the third score.
  69.  
  70. %Display interval average
  71. int_avg = weightedMean1 + weightedMean2 + weightedMean3;
  72. currentInt = num2str(i);
  73. fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
  74.  
  75. elseif buttonPresses(i) > 2 && buttonPresses(i) <=3
  76. %Initial input queries
  77. score1 = input('Enter the score preceding the first button press: '); % Score before the first button press.
  78. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured.
  79. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press.
  80. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred.
  81. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press.
  82. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred.
  83. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press.
  84.  
  85. %Time represented in the interval
  86. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  87. score2_int = time2 - time1; % Time that score2 is present in the interval.
  88. score3_int = time3 - time2; % Time that score3 is present in the interval.
  89. score4_int = (fix(time1/2)*2 + 2) - time3; % Time that score4 is present in the interval.
  90. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  91. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  92. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval.
  93. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval.
  94.  
  95. %Weighted means of each score by space in the interval.
  96. weightedMean1 = score1*perc_time1; % The weighted mean of the first score.
  97. weightedMean2 = score2*perc_time2; % The weighted mean of the second score.
  98. weightedMean3 = score3*perc_time3; % The weighted mean of the third score.
  99. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score.
  100.  
  101. %Display interval average
  102. int_avg = weightedMean1 + weightedMean2 + weightedMean3 + weightedMean4;
  103. currentInt = num2str(i);
  104. fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
  105.  
  106. elseif buttonPresses(i) > 3 && buttonPresses(i) <=4
  107. %Initial input queries
  108. score1 = input('Enter the score preceding the first button press: '); % Score before the first button press.
  109. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured.
  110. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press.
  111. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred.
  112. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press.
  113. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred.
  114. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press.
  115. time4 = input('Enter the time the fourth button press occurred: '); % Time that the fourth button press occurred.
  116. score5 = input('Enter the fifth score in the interval: '); % Score associated with the fourth button press.
  117.  
  118. %Time represented in the interval
  119. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  120. score2_int = time2 - time1; % Time that score2 is present in the interval.
  121. score3_int = time3 - time2; % Time that score3 is present in the interval.
  122. score4_int = time4 - time3; % Time that score4 is present in the interval.
  123. score5_int = (fix(time1/2)*2 + 2) - time4; % Time that score5 is present in the interval.
  124. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  125. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  126. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval.
  127. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval.
  128. perc_time5 = (score5_int)/2; % Time (in decimal format) that score5 is present in the interval.
  129.  
  130. %Weighted means of each score by space in the interval.
  131. weightedMean1 = score1*perc_time1; % The weighted mean of the first score.
  132. weightedMean2 = score2*perc_time2; % The weighted mean of the second score.
  133. weightedMean3 = score3*perc_time3; % The weighted mean of the third score.
  134. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score.
  135. weightedMean5 = score5*perc_time5; % The weighted mean of the fifth score.
  136.  
  137. %Display interval average
  138. int_avg = weightedMean1 + weightedMean2 + weightedMean3 +weightedMean4 + weightedMean5;
  139. currentInt = num2str(i);
  140. fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
  141.  
  142. elseif buttonPresses(i) > 4 && buttonPresses(i) <=5
  143. %Initial input queries
  144. score1 = input('Enter the score preceding the first button press: '); % Score before the first button press.
  145. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured.
  146. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press.
  147. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred.
  148. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press.
  149. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred.
  150. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press.
  151. time4 = input('Enter the time the fourth button press occurred: '); % Time that the fourth button press occurred.
  152. score5 = input('Enter the fifth score in the interval: '); % Score associated with the fourth button press.
  153. time5 = input('Enter the time the fifth button press occurred: '); % Time that the fifth button press occurred.
  154. score6 = input('Enter the sixth score in the interval: '); % Score associated with the fifth button press.
  155.  
  156. %Time represented in the interval
  157. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  158. score2_int = time2 - time1; % Time that score2 is present in the interval.
  159. score3_int = time3 - time2; % Time that score3 is present in the interval.
  160. score4_int = time4 - time3; % Time that score4 is present in the interval.
  161. score5_int = time5 - time4; % Time that score5 is present in the interval.
  162. score6_int = (fix(time1/2)*2 + 2) - time5; % Time that score6 is present in the interval.
  163. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  164. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  165. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval.
  166. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval.
  167. perc_time5 = (score5_int)/2; % Time (in decimal format) that score5 is present in the interval.
  168. perc_time6 = (score6_int)/2; % Time (in decimal format) that score5 is present in the interval.
  169.  
  170. %Weighted means of each score by space in the interval.
  171. weightedMean1 = score1*perc_time1; % The weighted mean of the first score.
  172. weightedMean2 = score2*perc_time2; % The weighted mean of the second score.
  173. weightedMean3 = score3*perc_time3; % The weighted mean of the third score.
  174. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score.
  175. weightedMean5 = score5*perc_time5; % The weighted mean of the fifth score.
  176. weightedMean6 = score6*perc_time6; % The weighted mean of the sixth score.
  177.  
  178. %Display interval average
  179. int_avg = weightedMean1 + weightedMean2 + weightedMean3 + weightedMean4 + weightedMean5 + weightedMean6;
  180. currentInt = num2str(i);
  181. fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
  182. else
  183. disp('You have encountered an error')
  184. break
  185. end
  186. end
  187. %% Close up shop
  188. fclose('all');
  189. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement