clear all; %% Initial input queries %% subID = input('Enter Subject ID (e.g. 201): ','s'); intervals = input('Enter the amount of intervals: '); valence = input('Was the video watched positive or negative?: ','s'); phase = input('Is this the target or perceiver phase?: ','s'); %% Create the structure for recording responses from the experiment: subjectStructName=sprintf('subject%s',subID); % Overwrite check: for i = 1:intervals currentTrial=num2str(i); outputFilename = sprintf('subject%s_%s_%s.txt',subID,phase,valence); if (exist(outputFilename,'file')==2) queryOverwriteString = sprintf('\nThe output for subject %s_%s_%s trial %s exists. Do you wish to OVERWRITE it [y/n]? ',subID,phase,valence,currentTrial); queryOverwrite = input(queryOverwriteString,'s'); if strcmpi(queryOverwrite, 'N') || strcmpi(queryOverwrite, 'NO') fprintf('Overwrite permission denied by user. Closing task...') return; else fprintf('The task will overwrite previous data.\n') fprintf('Press any key to continue or Ctrl+C to abort...\n\n') end; % if (strcmpi) end; % if (exist(outputFilename)==2) end; % for i = 1:numberTrials %% Record data and loop for i=1:intervals buttonPresses(i) = input('Enter the amount of button presses within the interval ');% Initial input queries queryEscape=false; % Flag for cancelling out of the script. queryRestart=false; % Flag for restarting current trial. querySkip=false; % Flag for skipping current trial. % Begin if/else logic to process data into weighted means if buttonPresses(i) <= 1 score1 = input('Enter the previous score: '); % Score before the first button press. score2 = input('Enter the current score: '); % Score of the first button press. time1 = input('Enter the response time: '); % Time that the first button press occured. score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval. score2_int = (fix(time1/2)*2 + 2) - time1; % Time that score2 is present in the interval. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval. weightedMean1 = score1*perc_time1; % The weighted mean of the score before the first button press. weightedMean2 = score2*perc_time2; % The weighted mean of the score after the first button press. %Display interval average int_avg = weightedMean1 + weightedMean2; sprintf('The interval average is %.3f',int_avg) elseif buttonPresses(i) > 1 && buttonPresses(i) <=2 %Initial input queries score1 = input('Enter the score preceding the first button press: '); % Score before the first button press. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press. %Time represented in the interval score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval. score2_int = time2 - time1; % Time that score2 is present in the interval. score3_int = (fix(time1/2)*2 + 2) - time2; % Time that score3 is present in the interval. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval. %Weighted means of each score by space in the interval. weightedMean1 = score1*perc_time1; % The weighted mean of the first score. weightedMean2 = score2*perc_time2; % The weighted mean of the second score. weightedMean3 = score3*perc_time3; % The weighted mean of the third score. %Display interval average int_avg = weightedMean1 + weightedMean2 + weightedMean3; sprintf('The interval average is %.3f',int_avg) elseif buttonPresses(i) > 2 && buttonPresses(i) <=3 %Initial input queries score1 = input('Enter the score preceding the first button press: '); % Score before the first button press. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press. %Time represented in the interval score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval. score2_int = time2 - time1; % Time that score2 is present in the interval. score3_int = time3 - time2; % Time that score3 is present in the interval. score4_int = (fix(time1/2)*2 + 2) - time3; % Time that score4 is present in the interval. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval. %Weighted means of each score by space in the interval. weightedMean1 = score1*perc_time1; % The weighted mean of the first score. weightedMean2 = score2*perc_time2; % The weighted mean of the second score. weightedMean3 = score3*perc_time3; % The weighted mean of the third score. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score. %Display interval average int_avg = weightedMean1 + weightedMean2 + weightedMean3 + weightedMean4; sprintf('The interval average is %.3f',int_avg) elseif buttonPresses(i) > 3 && buttonPresses(i) <=4 %Initial input queries score1 = input('Enter the score preceding the first button press: '); % Score before the first button press. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press. time4 = input('Enter the time the fourth button press occurred: '); % Time that the fourth button press occurred. score5 = input('Enter the fifth score in the interval: '); % Score associated with the fourth button press. %Time represented in the interval score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval. score2_int = time2 - time1; % Time that score2 is present in the interval. score3_int = time3 - time2; % Time that score3 is present in the interval. score4_int = time4 - time3; % Time that score4 is present in the interval. score5_int = (fix(time1/2)*2 + 2) - time4; % Time that score5 is present in the interval. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval. perc_time5 = (score5_int)/2; % Time (in decimal format) that score5 is present in the interval. %Weighted means of each score by space in the interval. weightedMean1 = score1*perc_time1; % The weighted mean of the first score. weightedMean2 = score2*perc_time2; % The weighted mean of the second score. weightedMean3 = score3*perc_time3; % The weighted mean of the third score. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score. weightedMean5 = score5*perc_time5; % The weighted mean of the fifth score. %Display interval average int_avg = weightedMean1 + weightedMean2 + weightedMean3 +weightedMean4 + weightedMean5; sprintf('The interval average is %.3f',int_avg) elseif buttonPresses(i) > 4 && buttonPresses(i) <=5 %Initial input queries score1 = input('Enter the score preceding the first button press: '); % Score before the first button press. time1 = input('Enter the time the first button press occurred: '); % Time that the first button press occured. score2 = input('Enter the second score in the interval: '); % Score associated with the first button press. time2 = input('Enter the time the second button press occured: '); % Time that the second button press occurred. score3 = input('Enter the third score in the interval: '); % Score associated with the second button press. time3 = input('Enter the time the third button press occured: '); % Time that the third button press occurred. score4 = input('Enter the fourth score in the interval: '); % Score associated with the third button press. time4 = input('Enter the time the fourth button press occurred: '); % Time that the fourth button press occurred. score5 = input('Enter the fifth score in the interval: '); % Score associated with the fourth button press. time5 = input('Enter the time the fifth button press occurred: '); % Time that the fifth button press occurred. score6 = input('Enter the sixth score in the interval: '); % Score associated with the fifth button press. %Time represented in the interval score1_int = time1 - fix(time1/2)*2; % Time that score1 is present in the interval. score2_int = time2 - time1; % Time that score2 is present in the interval. score3_int = time3 - time2; % Time that score3 is present in the interval. score4_int = time4 - time3; % Time that score4 is present in the interval. score5_int = time5 - time4; % Time that score5 is present in the interval. score6_int = (fix(time1/2)*2 + 2) - time5; % Time that score6 is present in the interval. perc_time1 = (score1_int)/2; % Time (in decimal format) that score1 is present in the interval. perc_time2 = (score2_int)/2; % Time (in decimal format) that score2 is present in the interval. perc_time3 = (score3_int)/2; % Time (in decimal format) that score3 is present in the interval. perc_time4 = (score4_int)/2; % Time (in decimal format) that score4 is present in the interval. perc_time5 = (score5_int)/2; % Time (in decimal format) that score5 is present in the interval. perc_time6 = (score6_int)/2; % Time (in decimal format) that score5 is present in the interval. %Weighted means of each score by space in the interval. weightedMean1 = score1*perc_time1; % The weighted mean of the first score. weightedMean2 = score2*perc_time2; % The weighted mean of the second score. weightedMean3 = score3*perc_time3; % The weighted mean of the third score. weightedMean4 = score4*perc_time4; % The weighted mean of the fourth score. weightedMean5 = score5*perc_time5; % The weighted mean of the fifth score. weightedMean6 = score6*perc_time6; % The weighted mean of the sixth score. %Display interval average int_avg = weightedMean1 + weightedMean2 + weightedMean3 + weightedMean4 + weightedMean5 + weightedMean6; sprintf('The interval average is %.3f',int_avg) % Open output file and print header line: outputFilename = sprintf('subject%s_%s_%s.txt',subID,phase,valence); fid = fopen(outputFilename,'wt'); fprintf(fid,'Interval\tWeightedMean\tValence\tPhase\tsubID\n'); fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',Interval,int_avg(i),valence, phase, subID); eval outputFilename; else disp('You have encountered an error')