%function results = ImportAll(folder, subNum, control, followUp, plotRawData, plotFiltData) % [fileName, folder] = uigetfile('.xlsx', 'Please select the raw Excel data file with the subject numbers'); %folder = '/Users/u5331246/Dropbox/ANU/collaborations/Mandi_SPD/SPD Sway/'; % subNum = 10913; control = 0; followUp = 0; plotRawData = 0; plotFiltData = 0; group = 'HN'; [SPD, HN, SZ] = importExcelSubNumbers(folder, fileName); % calls a little function I wrote to use an Excel file to store the numbers of valid subjects. %% To do: Make this nicer! if strcmp(group, 'SPD') subnums = SPD; elseif strcmp(group, 'HN') subnums = HN; elseif strcmp(group, 'SZ') subnums = SZ; else error('Group must be SPD,HN, or SZ!') end %% for i = 1:length(subnums) sub = subnums(i); subNum = num2str(sub); resultsDir = [folder, '/RESULTS/' group, '/', num2str(subNum)]; if ~exist ( resultsDir, 'dir') mkdir (resultsDir) end if ~exist([resultsDir, '/', num2str(subNum) '_SwayData_AllConds.mat'], 'file') count = 1; % slight hack to tell us where to put each row of data for eyeCondition = 1:2 % a loop to work out the condition name string for baseCondition = 1:2 if eyeCondition == 1 eye = 'EO'; else eye = 'EC'; end if baseCondition == 1 base = 'OB'; else base = 'CB'; end ConditionName = [ eye, base, 'COP.txt']; % string to input into the function we're going to call next [AP_Sway, ML_Sway] = ImportSPDSwayTextFiles(folder, subNum, ConditionName, plotRawData); %% uncomment this section to run a Butterworth filter on the data fs = 200; % sampling frequency Hz = 25; % cutoff frequency for filter Wn = Hz/(fs/2); [b,a]=butter(5, Wn, 'low'); % low-pass order 5 Butterworth filter AP_Sway_filt=filter(b,a,AP_Sway); ML_Sway_filt =filter(b,a, ML_Sway); %% results.AP_All(:, count) = AP_Sway; results.ML_All(:, count) = ML_Sway; results.AP_All_filt(:, count) = AP_Sway_filt; results.ML_All_filt(:, count) = ML_Sway_filt; %% count = count+1; end end %% plot data if plotFiltData figure; Xmin = min(min(results.ML_All_filt)); Xmax = max(max(results.ML_All_filt)); Ymin = min(min(results.AP_All_filt)); Ymax = max(max(results.AP_All_filt)); for count = 1:4 switch count case 1 eye = 'Open'; base = 'Open'; col = 'b'; case 2 eye = 'Open'; base = 'Closed'; col = 'b'; case 3 eye = 'Closed'; base = 'Open'; col = 'r'; case 4 eye = 'Closed'; base = 'Closed'; col = 'r'; end subplot(2, 2,count) plot (results.ML_All_filt(:, count), results.AP_All_filt(:, count), col); xlabel('ML CoP change', 'FontSize', 14) ylabel('AP CoP change', 'FontSize', 14) axis([Xmin Xmax Ymin Ymax]); axis equal; title([num2str(subNum) ' Eyes ' eye, ' Base ', base], 'FontSize', 20) end end %% Save results save ([resultsDir, '/', num2str(subNum) '_SwayData_AllConds'], 'results') clear results end end