-
Notifications
You must be signed in to change notification settings - Fork 0
/
callChronuxCoherency.m
108 lines (105 loc) · 4.36 KB
/
callChronuxCoherency.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
function [ varargout ] = callChronuxCoherency( funcHandle, varargin)
%callChronuxCoherency runs Chronux coherency functions such that nargout is
%independent of the error calculation type, as specified in params.err(1)
% Chronux demands that the number of output arguments match the error
% computation type. This means that you need to write out a separate call
% for every error computation type. This function removes that need.
% Inputs: funcHandle - a function handle to one of:
% coherencyc, coherencycpt, coherencycpb, coherencypt, coherencypb, cohgramc,
% cohgramcpt, cohgramcpb, cohgrampt, cohgrampb
% Returns: the longest possible set of chronux coherency outputs
% - for field-field, [ C,phi,S12,S1,S2,f,confC,phistd,Cerr ]
% - for all others, [ C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr ]
% - uncomputed errors are set to NaN
% Example:
% - [ C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr ] = callChronuxCoherency(@coherencycpb,lfpData,spikeData,chronuxParams)
funcString = func2str(funcHandle);
assert(strcmp(funcString,'coherencyc') || strcmp(funcString,'coherencycpt') || strcmp(funcString,'coherencycpb')|| ...
strcmp(funcString,'cohgramc') || strcmp(funcString,'cohgramcpt') || strcmp(funcString,'cohgramcpb') || ...
strcmp(funcString,'coherencypt') || strcmp(funcString,'coherencypb') || ...
strcmp(funcString,'cohgrampt') || strcmp(funcString,'cohgrampb'), ...
sprintf('Invalid function handle @%s. Acceptable values are: coherencyc, coherencycpt, coherencycpb, coherencypt, coherencypb, cohgramc, cohgramcpt, cohgramcpb, cohgrampt, cohgrampb',...
funcString));
assert(isstruct(varargin{end}) && isfield(varargin{end},'err') && any(varargin{end}.err(1) == [0 1 2]), 'Invalid chronux params');
if ~isempty(regexp(funcString,'gram','ONCE'))
if ~isempty(regexp(funcString,'pt','ONCE')) || ~isempty(regexp(funcString,'pb','ONCE'))
if varargin{end}.err(1) == 2
[ C,phi,S12,S1,S2,t,f,zerosp,confC,phistd,Cerr ] = funcHandle(varargin{:});
varargout = {C,phi,S12,S1,S2,t,f,zerosp,confC,phistd,Cerr};
return
end
if varargin{end}.err(1) == 1
[ C,phi,S12,S1,S2,t,f,zerosp,confC,phistd ] = funcHandle(varargin{:});
Cerr = NaN;
varargout = {C,phi,S12,S1,S2,t,f,zerosp,confC,phistd,Cerr};
return
else
[ C,phi,S12,S1,S2,t,f,zerosp ] = funcHandle(varargin{:});
Cerr = NaN;
confC = NaN;
phistd = NaN;
varargout = {C,phi,S12,S1,S2,t,f,zerosp,confC,phistd,Cerr};
return
end
else
if varargin{end}.err(1) == 2
[ C,phi,S12,S1,S2,t,f,confC,phistd,Cerr ] = funcHandle(varargin{:});
varargout = {C,phi,S12,S1,S2,t,f,confC,phistd,Cerr};
return
end
if varargin{end}.err(1) == 1
[ C,phi,S12,S1,S2,t,f,confC,phistd ] = funcHandle(varargin{:});
Cerr = NaN;
varargout = {C,phi,S12,S1,S2,t,f,confC,phistd,Cerr};
return
else
[ C,phi,S12,S1,S2,t,f ] = funcHandle(varargin{:});
Cerr = NaN;
confC = NaN;
phistd = NaN;
varargout = {C,phi,S12,S1,S2,t,f,confC,phistd,Cerr};
return
end
end
else
if ~isempty(regexp(funcString,'pt','ONCE')) || ~isempty(regexp(funcString,'pb','ONCE'))
if varargin{end}.err(1) == 2
[ C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr ] = funcHandle(varargin{:});
varargout = {C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr};
return
end
if varargin{end}.err(1) == 1
[ C,phi,S12,S1,S2,f,zerosp,confC,phistd ] = funcHandle(varargin{:});
Cerr = NaN;
varargout = {C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr};
return
else
[ C,phi,S12,S1,S2,f,zerosp ] = funcHandle(varargin{:});
Cerr = NaN;
confC = NaN;
phistd = NaN;
varargout = {C,phi,S12,S1,S2,f,zerosp,confC,phistd,Cerr};
return
end
else
if varargin{end}.err(1) == 2
[ C,phi,S12,S1,S2,f,confC,phistd,Cerr ] = funcHandle(varargin{:});
varargout = {C,phi,S12,S1,S2,f,confC,phistd,Cerr};
return
end
if varargin{end}.err(1) == 1
[ C,phi,S12,S1,S2,f,confC,phistd ] = funcHandle(varargin{:});
Cerr = NaN;
varargout = {C,phi,S12,S1,S2,f,confC,phistd,Cerr};
return
else
[ C,phi,S12,S1,S2,f ] = funcHandle(varargin{:});
Cerr = NaN;
confC = NaN;
phistd = NaN;
varargout = {C,phi,S12,S1,S2,f,confC,phistd,Cerr};
return
end
end
end
end