-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConvert_MATLAB_data.m
83 lines (68 loc) · 2.56 KB
/
Convert_MATLAB_data.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
%% Setup
% Add folders with functions
addpath('MATLAB_data','data');
% specfiy experiments
experiments = {
'E01' ; 'E2'; 'E3'; 'E4'; 'E5';
'E6';'E7';'E8';'E9';'E10'
};
% get all expfiles
expfiles = dir('MATLAB_data\');
expfiles_names = {expfiles.name};
% Loop thourgh experiments
for e = 1:size(experiments,1)
exp = experiments{e};
this_expFiles_IDs = regexp(expfiles_names, exp, 'start');
this_expFiles_IDs = ~cellfun('isempty', this_expFiles_IDs);
print_header = 0;
for d = 1:size(expfiles,1)
if this_expFiles_IDs(d) == 0
continue
else
data = load([expfiles(d).folder,'\',expfiles(d).name]);
subID = erase(expfiles(d).name, exp);
subID = erase(subID, '_subject_');
subID = erase(subID, '.mat');
subID = str2double(subID);
expName = data.experiment_name{1};
expName = erase(expName,' et al. ');
expName = erase(expName,' ');
subData = data.data;
dataFile = ['data\', expName, '.txt'];
if print_header == 0
fid = fopen(dataFile, 'a');
% Print header into data file
fprintf (fid, '%s %s %s %s ', 'subID', 'trial', 'setsize', 'RespErr');
for i = 1:10
% Print retrieval specific inforamtion into data file
fprintf (fid, '%s ', ['Pos_Lure',num2str(i)]);
end
% Print new Line after each trial
fprintf (fid, '\n');
fclose (fid);
% Set print_header to 1
print_header = 1;
end
for t = 1:size(subData.error_vec,2)
error = subData.error_vec(t);
setsize = subData.N(t);
lures = subData.dist_error_vec{t};
fid = fopen(dataFile, 'a');
% Print general information (constant over Trial(expTrial)) into data file
fprintf (fid, '%d %i %i %d ', subID, t, setsize, error);
for i = 1:10
if i > size(lures,1)
% Print NA for lure position into data file
fprintf (fid, '%s ', 'NA');
else
% Print lure positions into data file
fprintf (fid, '%d ', lures(i));
end
end
% Print new Line after each trial
fprintf (fid, '\n');
fclose (fid);
end
end
end
end