Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function process_interval_loop
- % Velez Valence Processing v.01
- %
- % The script is intended to expedite the valence scoring of the EA_EEG
- % experiments for both targets and perceivers. It requires a computer with
- % MATLAB 7 installed.
- clc;
- 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');
- %% Open file for writing output
- outputFilename = sprintf('subject%s_%s_%s.txt',subID,phase,valence);
- fid = fopen(outputFilename,'w+');
- fprintf(fid,'IntervalNumber\tWeightedAvg\tPhase\tValence\tsubID\n'); % Write headers on text file
- %% Record data and loop
- for i=1:intervals
- buttonPresses(i) = input('Enter the amount of button presses within the interval ');% Initial input queries
- % No button presses
- if buttonPresses(i) == 0
- score = input('Enter the only score in the interval');
- int_avg = score;
- currentInt = num2str(i); % What stage of the loop are we in
- fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
- % Begin if/else logic to process data into weighted means
- elseif buttonPresses(i) > 0 && 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;
- currentInt = num2str(i); % What stage of the loop are we in
- fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
- 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;
- currentInt = num2str(i);
- fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
- 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;
- currentInt = num2str(i);
- fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
- 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;
- currentInt = num2str(i);
- fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
- 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;
- currentInt = num2str(i);
- fprintf(fid,'%s\t%.3f\t%s\t%s\t%s\n',currentInt,int_avg,phase,valence,subID);
- else
- disp('You have encountered an error')
- break
- end
- end
- %% Close up shop
- fclose('all');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement