-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportSummary.m
128 lines (110 loc) · 4.11 KB
/
exportSummary.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function exportSummary(summaryFile)
%% export summary file to excel format
% summaryFile = 'results/Summary-Trained-Sorted.mat';
% summaryFile = 'results/Summary-Naive-Sorted.mat';
if length(summaryFile)<4 || ~strcmpi(summaryFile(end-3:end), '.mat')
error('[exportSummary] Need a .mat file');
end
% exportFile = [summaryFile(1:end-4) '.xlsx'];
exportFile = [summaryFile(1:end-4) '.csv'];
fprintf('Exporting as csv to %s\n', exportFile);
% only export active/passive MMR, not quiet
modes = {'Active', 'Passive'};
scoresGo = {'All', 'HIT', 'MISS'};
scoresNogo = {'All', 'CA', 'FA'};
% prep table headers
% headers = struct();
% headers.Intervals = ... % per interval: onset/peri/offset ...
% {'SubjectID' 'UnitID' 'Group' 'Category' 'SubCategory' ...
% 'Mode' 'TargetLevel' 'Score' 'Interval' ...
% 'TER' 'TEP' 'dPrime' 'FRMean' 'FRMax' 'MutualInfo' ...
% 'VS10' 'VS10Phase' 'VS10PVal' 'MTS10' 'CorrR' 'CorrP'};
% prep tables as empty cells
% tableNames = fieldnames(headers);
% tables = struct();
% for tableID = 1:length(tableNames)
% tables.(tableNames{tableID}) = {};
% end
f = fopen(exportFile, 'w');
fprintf(f, ['SubjectID,SessionID,UnitID,Group,Category,SubCategory,' ...
'Mode,TargetLevel,Score,Interval,' ...
'BehavDPrime,RateDPrime,DecorrDPrime,' ...
'TER,TEP,FRMean,FRMax,MutualInfo,' ...
'VS10,VS10Phase,VS10PVal,MTS10,CorrR,CorrP\n']);
% load summary analysis
load(summaryFile, 'analysis');
a = analysis{1};
% iterate through different recording modes stored as summary units
for modeID = 1:length(modes)
mode = modes{modeID};
u = a.units{modeID};
for condID = 1:u.condCount
levelID = condID-1;
if levelID
level = u.targetLevels(levelID);
else
level = 0;
end
for scoreID = 1:3
% passive recordings don't have a score
if modeID~=1 && scoreID>1; continue; end
if condID == 1
score = scoresNogo{scoreID};
else
score = scoresGo{scoreID};
end
for i = 1:length(u.unitIDs)
subjectID = u.animalNames{i};
sessionID = u.sessionIDs(i);
unitID = u.unitIDs(i);
group = u.group;
category = u.category{i};
subCategory = u.subCategory{i};
% for onset/peri/offset/perifull
for intervalID = 1:u.i.count
intervalName = u.i.names{intervalID};
behavDP = u.dPrimeBehavior{condID}(i);
rateDP = u.i.dPrime{condID,scoreID}(i,intervalID);
decorrDP = u.decorrDPrime{condID,scoreID}(i);
ter = u.i.ter{condID,scoreID}(i,intervalID);
tep = u.i.tep{condID,scoreID}(i,intervalID);
firingMean = u.i.frMean{condID,scoreID}(i,intervalID);
firingMax = u.i.frMax{condID,scoreID}(i,intervalID);
mutualInfo = u.i.mutualInfo{condID,scoreID}(i,intervalID);
if isinf(mutualInfo); mutualInfo = nan; end
vs10 = u.i.vs10{condID,scoreID}(i,intervalID);
vs10Phase = u.i.vs10Phase{condID,scoreID}(i,intervalID);
vs10PVal = u.i.vs10PVal{condID,scoreID}(i,intervalID);
mts10 = u.i.mts10{condID,scoreID}(i,intervalID);
corrR = u.i.corrR{condID,scoreID}(i,intervalID);
corrP = u.i.corrP{condID,scoreID}(i,intervalID);
% tables.Intervals(end+1,:) = ...
% {animaName unitID category subCategory ...
% mode level score intervalName ...
% ter tep dp firingMean firingMax mutualInfo ...
% vs10 vs10Phase vs10PVal mts10 corrR corrP};
fprintf(f, ['%s,%d,%d,%s,%s,%s,' ...
'%s,%d,%s,%s,' ...
'%d,%d,%d,' ...
'%d,%d,%d,%d,%d,' ...
'%d,%d,%d,%d,%d,%d\n'], ...
subjectID, sessionID, unitID, group, category, subCategory, ...
mode, level, score, intervalName, ...
behavDP, rateDP, decorrDP, ...
ter, tep, firingMean, firingMax, mutualInfo, ...
vs10, vs10Phase, vs10PVal, mts10, corrR, corrP);
end
end
end
end
end
% write tables to excel file
% warning( 'off', 'MATLAB:xlswrite:AddSheet');
% if exist(exportFile, 'file'); delete(exportFile); end
% for tableID = 1:length(tableNames)
% name = tableNames{tableID};
% t = cell2table(tables.(name), 'variablenames', headers.(name));
% writetable(t, exportFile, 'sheet', name);
% end
fclose(f);
end