-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_sourcedata.m
66 lines (44 loc) · 1.35 KB
/
extract_sourcedata.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% Initialization
clear all;
close all;
clc;
% Daniel Sazhin
% 03/15/24
% Neuroeconomics Lab
% Temple University.
% StayGo 2 Project
% This code takes in the main spreadsheet and outputs into sourcedata.
% Outputs: Participant folder and file.
%%
[pathstr,~,~] = fileparts(pwd);
usedir = pathstr;
rawdatadir = fullfile(usedir,'bids','sourcedata','Qualtrics_sourcedata.xlsx');
[n,t,rawdata] = xlsread(rawdatadir);
headers = t(1,:); % Pulls out the headers
data = rawdata(3:end,:); % Participant data
[N,~]=size(data); % Total Subjects
[pathstr,name,ext] = fileparts(pwd);
usedir = pathstr;
%[pathstr2,name,ext] = fileparts(usedir)
maindir = fullfile(usedir,'bids');
%%
sub_list = [];
for ii = 1:N
partnum = num2str(ii,'%03.f');
outputdir_name = fullfile(maindir,'sourcedata',(['sub-' partnum]));
if isfolder(outputdir_name) == 1
rmdir(outputdir_name, 's')
end
mkdir(outputdir_name);
raw_participant = data(ii,:);
participant = [headers;raw_participant];
tempname = fullfile(outputdir_name,(['sub-' partnum]));
filename = [tempname '.xlsx'];
writecell(participant,filename);% Save file in table form
sub_list = [sub_list;partnum];
end
filename = fullfile(pwd,'Subjects_Before_Exclusions.txt');
if isfile(filename) == 1
delete(filename)
end
writematrix(sub_list, filename); % Save file in table form