Advertisement
limah

PL_loop

Feb 24th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.34 KB | None | 0 0
  1. clear all;
  2.  
  3. %% Initial input queries %%
  4. subID = input('Enter Subject ID (e.g. 201): ','s');
  5. intervals = input('Enter the amount of intervals: ');
  6. valence = input('Was the video watched positive or negative?: ','s');
  7. phase = input('Is this the target or perceiver phase?: ','s');
  8.  
  9. %% Create the structure for recording responses from the experiment:
  10. subjectStructName=sprintf('subject%s',subID);
  11.  
  12. % Overwrite check:
  13. for i = 1:intervals
  14. currentTrial=num2str(i);
  15. outputFilename = sprintf('subject%s_%s_%s.txt',subID,phase,valence);
  16. if (exist(outputFilename,'file')==2)
  17. queryOverwriteString = sprintf('\nThe output for subject %s_%s_%s trial %s exists. Do you wish to OVERWRITE it [y/n]? ',subID,phase,valence,currentTrial);
  18. queryOverwrite = input(queryOverwriteString,'s');
  19. if strcmpi(queryOverwrite, 'N') || strcmpi(queryOverwrite, 'NO')
  20. fprintf('Overwrite permission denied by user. Closing task...')
  21. return;
  22. else
  23. fprintf('The task will overwrite previous data.\n')
  24. fprintf('Press any key to continue or Ctrl+C to abort...\n\n')
  25. end; % if (strcmpi)
  26. end; % if (exist(outputFilename)==2)
  27. end; % for i = 1:numberTrials
  28. %% Record data and loop
  29. for i=1:intervals
  30. buttonPresses(i) = input('Enter the amount of button presses within the interval ');% Initial input queries
  31. queryEscape=false; % Flag for cancelling out of the script.
  32. queryRestart=false; % Flag for restarting current trial.
  33. querySkip=false; % Flag for skipping current trial.
  34.  
  35. % Begin if/else logic to process data into weighted means
  36. if buttonPresses(i) <= 1
  37. score1 = input('Enter the previous score: '); % Score before the first button press.
  38. score2 = input('Enter the current score: '); % Score of the first button press.
  39. time1 = input('Enter the response time: '); % Time that the first button press occured.
  40. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  41. score2_int = (fix(time1/2)*2 + 2) - time1; % Time that score2 is present in the interval.
  42. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  43. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  44. weightedMean1 = score1*perc_time1; % The weighted mean of the score before the first button press.
  45. weightedMean2 = score2*perc_time2; % The weighted mean of the score after the first button press.
  46.  
  47. %Display interval average
  48. int_avg = weightedMean1 + weightedMean2;
  49. sprintf('The interval average is %.3f',int_avg)
  50.  
  51. elseif buttonPresses(i) > 1 && buttonPresses(i) <=2
  52. %Initial input queries
  53. score1 = input('Enter the score preceding the first button press: '); % Score before the first button press.
  54. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured.
  55. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press.
  56. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred.
  57. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press.
  58.  
  59. %Time represented in the interval
  60. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  61. score2_int = time2 - time1; % Time that score2 is present in the interval.
  62. score3_int = (fix(time1/2)*2 + 2) - time2; % Time that score3 is present in the interval.
  63. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  64. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  65. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval.
  66.  
  67. %Weighted means of each score by space in the interval.
  68. weightedMean1 = score1*perc_time1; % The weighted mean of the first score.
  69. weightedMean2 = score2*perc_time2; % The weighted mean of the second score.
  70. weightedMean3 = score3*perc_time3; % The weighted mean of the third score.
  71.  
  72. %Display interval average
  73. int_avg = weightedMean1 + weightedMean2 + weightedMean3;
  74. sprintf('The interval average is %.3f',int_avg)
  75.  
  76. elseif buttonPresses(i) > 2 && buttonPresses(i) <=3
  77. %Initial input queries
  78. score1 = input('Enter the score preceding the first button press: '); % Score before the first button press.
  79. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured.
  80. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press.
  81. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred.
  82. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press.
  83. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred.
  84. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press.
  85.  
  86. %Time represented in the interval
  87. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  88. score2_int = time2 - time1; % Time that score2 is present in the interval.
  89. score3_int = time3 - time2; % Time that score3 is present in the interval.
  90. score4_int = (fix(time1/2)*2 + 2) - time3; % Time that score4 is present in the interval.
  91. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  92. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  93. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval.
  94. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval.
  95.  
  96. %Weighted means of each score by space in the interval.
  97. weightedMean1 = score1*perc_time1; % The weighted mean of the first score.
  98. weightedMean2 = score2*perc_time2; % The weighted mean of the second score.
  99. weightedMean3 = score3*perc_time3; % The weighted mean of the third score.
  100. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score.
  101.  
  102. %Display interval average
  103. int_avg = weightedMean1 + weightedMean2 + weightedMean3 + weightedMean4;
  104. sprintf('The interval average is %.3f',int_avg)
  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. sprintf('The interval average is %.3f',int_avg)
  140.  
  141. elseif buttonPresses(i) > 4 && buttonPresses(i) <=5
  142. %Initial input queries
  143. score1 = input('Enter the score preceding the first button press: '); % Score before the first button press.
  144. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured.
  145. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press.
  146. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred.
  147. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press.
  148. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred.
  149. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press.
  150. time4 = input('Enter the time the fourth button press occurred: '); % Time that the fourth button press occurred.
  151. score5 = input('Enter the fifth score in the interval: '); % Score associated with the fourth button press.
  152. time5 = input('Enter the time the fifth button press occurred: '); % Time that the fifth button press occurred.
  153. score6 = input('Enter the sixth score in the interval: '); % Score associated with the fifth button press.
  154.  
  155. %Time represented in the interval
  156. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval.
  157. score2_int = time2 - time1; % Time that score2 is present in the interval.
  158. score3_int = time3 - time2; % Time that score3 is present in the interval.
  159. score4_int = time4 - time3; % Time that score4 is present in the interval.
  160. score5_int = time5 - time4; % Time that score5 is present in the interval.
  161. score6_int = (fix(time1/2)*2 + 2) - time5; % Time that score6 is present in the interval.
  162. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval.
  163. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval.
  164. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval.
  165. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval.
  166. perc_time5 = (score5_int)/2; % Time (in decimal format) that score5 is present in the interval.
  167. perc_time6 = (score6_int)/2; % Time (in decimal format) that score5 is present in the interval.
  168.  
  169. %Weighted means of each score by space in the interval.
  170. weightedMean1 = score1*perc_time1; % The weighted mean of the first score.
  171. weightedMean2 = score2*perc_time2; % The weighted mean of the second score.
  172. weightedMean3 = score3*perc_time3; % The weighted mean of the third score.
  173. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score.
  174. weightedMean5 = score5*perc_time5; % The weighted mean of the fifth score.
  175. weightedMean6 = score6*perc_time6; % The weighted mean of the sixth score.
  176.  
  177. %Display interval average
  178. int_avg = weightedMean1 + weightedMean2 + weightedMean3 + weightedMean4 + weightedMean5 + weightedMean6;
  179. sprintf('The interval average is %.3f',int_avg)
  180.  
  181. % Open output file and print header line:
  182. outputFilename = sprintf('subject%s_%s_%s.txt',subID,phase,valence);
  183. fid = fopen(outputFilename,'wt');
  184. fprintf(fid,'Interval\tWeightedMean\tValence\tPhase\tsubID\n');
  185. fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',Interval,int_avg(i),valence, phase, subID);
  186. eval outputFilename;
  187.  
  188. else
  189. disp('You have encountered an error')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement