forked from LabNeuroCogDevel/CogEmoFaceReward
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockToCSV.m
More file actions
47 lines (38 loc) · 1.53 KB
/
ClockToCSV.m
File metadata and controls
47 lines (38 loc) · 1.53 KB
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
function ClockToCSV(filename, fieldnames)
%helper function
function st = cell2str(cellStr)
if isempty(cellStr)
st='';
else
%add a num2str to each conversion so that numeric and char data are handled properly
cellStr= cellfun(@(x){[num2str(x) ',']},cellStr); %# Add ',' after each string.
st = cat(2,cellStr{:}); %# Convert to string
st(end) = []; %# Remove last ','
end
end
%verify file existence
if ~exist(filename,'file'), error('cannot find file: %s\n', filename); end
%load behavioral results into local structure
fdata=load(filename);
if nargin < 2
if ismember('orderfmt',fields(fdata))
fieldnames=fdata.orderfmt; %order of fields saved in more recent versions of task
else
%if fieldnames not specified, these are the default
fieldnames = { 'run', 'trial', 'rewFunc', 'emotion', 'magnitude', 'probability', 'score', 'ev', 'rt', 'clock_onset', ...
'isi_onset', 'feedback_onset', 'iti_onset' 'iti_ideal' 'image' };
end
end
%derive new filename based on input
[name.path,name.name,name.ext]=fileparts(filename);
outfile=fullfile(name.path, sprintf('%s_tcExport.csv', name.name));
%open text file for writing
fid=fopen(outfile, 'w');
%write field header to file
fprintf(fid, '%s\n', cell2str(fieldnames));
%write each row as a comma-separated string to file
for i = 1:size(fdata.order,1)
fprintf(fid, '%s\n', cell2str(fdata.order{i}));
end
fclose(fid);
end