-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremovebaddvdt.m
More file actions
70 lines (70 loc) · 2.2 KB
/
removebaddvdt.m
File metadata and controls
70 lines (70 loc) · 2.2 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [output outputdvdt1loc] = removebaddvdt(pklocations, timepointstouse,dvdt1loc)
output = [];
outputdvdt1loc = [];
for i = 1:length(pklocations)
vector = timepointstouse;
vectordvdt1loc = dvdt1loc;
if ismember(output,vector)
tf = ismember(output,vector);
vector(tf) = [];
vectordvdt1loc(tf) = [];
end
usethis = [];
usethisdvdt1loc = [];
b = pklocations(i); % the peak of one of the spikes
while isempty(usethis)
[~,I] = min(abs(vector-b)); % the closest threshold value to the peak
c = vector(I);
cdvdt1loc = vectordvdt1loc(I);
if c < pklocations(i) % if peak happens after threshold
usethis = c; % use that threshold
usethisdvdt1loc = cdvdt1loc;
vector(I) = []; % delete that threshold value from "vector"
vectordvdt1loc(I) = [];
else
vector(I) = [];
vectordvdt1loc(I) = [];
end
if isempty(vector)
break % terminate while loop if vector becomes empty
end
end
if ~isempty(usethis)
output(1,i) = usethis;
outputdvdt1loc(1,i) = usethisdvdt1loc;
else
output(1,i) = NaN;
outputdvdt1loc(1,i) = NaN;
end
end
outputdvdt1loc(isnan(outputdvdt1loc)) = []; % removes NaN
%% ORIGINAL COPY - only outputs thresholds. Newer version above outputs thresholds AND updated dvdt1loc
% function [output] = removebaddvdt(pklocations, timepointstouse)
% output = [];
% for i = 1:length(pklocations)
% vector = timepointstouse;
% if ismember(output,vector)
% tf = ismember(output,vector);
% vector(tf) = [];
% end
% usethis = [];
% b = pklocations(i);
% while isempty(usethis)
% [~,I] = min(abs(vector-b));
% c = vector(I);
% if c < pklocations(i) % if peak happens after threshold
% usethis = c;
% vector(I) = [];
% else
% vector(I) = [];
% end
% if isempty(vector)
% break
% end
% end
% if ~isempty(usethis)
% output(1,i) = usethis;
% else
% output(1,i) = NaN;
% end
% end