-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeling_CropRecording.m
More file actions
executable file
·36 lines (31 loc) · 1.52 KB
/
Modeling_CropRecording.m
File metadata and controls
executable file
·36 lines (31 loc) · 1.52 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Janez Presern, Ales Skorjanc, Tomaz Rodic, Jan Benda 2011-2015
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Utility cropping recording at the desired length (at the end of
% relevance) as set in InitFitParam
function output = Modeling_CropRecording(rec_ti,rec_ampi,dt,stim_t,RecShift)
for dr = 1:length(rec_ti);
if isnan(rec_ti{dr}) == 0 % ignore, if only NaNs
RecordingTime(dr,:) = 0:dt:sum(stim_t(dr,:));
Recording_t = rec_ti{dr} - RecShift;
Recording_amp = rec_ampi{dr};
RecordingAmp(dr,:) = interp1(Recording_t,Recording_amp,RecordingTime(dr,:));
%%%%%%%%%% Replace NaNs with the closest non-NaN number %%%%%%%%%
if isnan(sum(RecordingAmp(dr,:)))
Ind_NaN = find(isnan(RecordingAmp(dr,:)));
if isempty(find(diff(Ind_NaN) > 1, 1));
if Ind_NaN(1) == 1
RecordingAmp(dr,Ind_NaN) = RecordingAmp(dr,Ind_NaN(end) + 1);
else
RecordingAmp(dr,Ind_NaN) = RecordingAmp(dr,Ind_NaN(1) - 1);
end;
else
ind_break = find(diff(Ind_NaN) ~= 1);
RecordingAmp(dr,Ind_NaN(1:ind_break)) = RecordingAmp(dr,Ind_NaN(ind_break) + 1);
RecordingAmp(dr,Ind_NaN(ind_break:end)) = RecordingAmp(dr,Ind_NaN(ind_break+1) - 1);
end;
end;
end;
end;
output.rec_t = RecordingTime;
output.rec_amp = RecordingAmp;