-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportStimEvents.m
53 lines (40 loc) · 2.05 KB
/
exportStimEvents.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
function exportStimEvents(data, saveFile, exportFile)
%% exportStimEvents(data, saveFile, exportFile)
%
% Function to export csv file of all stim event stats
% Handle input arguments - if not entered
if (nargin < 3); exportFile = []; end
if (nargin < 2); saveFile = []; end
if (nargin < 1); data = []; end
if isempty(data) || isempty(saveFile)
error('Enter sufficient inputs to use function exportStimEvents');
end
if isempty(exportFile)
[parentPath, saveFileName, ~] = parsePath(saveFile);
defaultName = [parentPath saveFileName '_StimEvents.csv'];
[exportName, exportPath] = uiputfile('.csv','Select *.csv file to export table of stimulation events', defaultName);
exportFile = [exportPath exportName];
if ~all(exportFile); error('No stimulation events to be exported - no file selected'); end
end
colNames{data.stim.Ca.nEventsA} = [];
for i = 1:data.stim.Ca.nEventsA
colNames{i} = strcat('stim', num2str(i));
end
rowNames = {'stimStart'; 'stimEnd'; 'stimPeak'; 'lfpAmp'; 'lfpBL'; 'lfpSlope'; 'nCellsActive'};
peakNames{data.Ca.nChannels, 1} = [];
areaNames{data.Ca.nChannels, 1} = [];
boolNames{data.Ca.nChannels, 1} = [];
for i = 1:data.Ca.nChannels
peakNames{i} = strcat('Cell', num2str(i), '_Peak');
areaNames{i} = strcat('Cell', num2str(i), '_Area');
boolNames{i} = strcat('Cell', num2str(i));
end
rowNames = [rowNames; peakNames; areaNames; boolNames];
varArray = vertcat(data.stim.evStart', data.stim.evEnd', data.stim.evPeak', data.stim.lfpAmp', data.stim.lfpBL', data.stim.lfpSlope', data.stim.Ca.nCellsC', data.Ca.stim.evPeakStim', data.Ca.stim.evAreaStim', data.stim.Ca.evMatrix');
outTable = array2table(varArray, 'VariableNames', colNames, 'RowNames', rowNames);
% Replace NaN values with blanks
tmp = table2cell(outTable);
tmp(isnan(outTable.Variables)) = {[]};
outTable = array2table(tmp, 'VariableNames', outTable.Properties.VariableNames, 'RowNames', outTable.Properties.RowNames);
writetable(outTable, exportFile, 'Delimiter', ',', 'WriteVariableNames', 1, 'WriteRowNames', 1);
end