-
Notifications
You must be signed in to change notification settings - Fork 2
/
MakePulseModelMulti.m
70 lines (56 loc) · 2.23 KB
/
MakePulseModelMulti.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
function MakePulseModelMulti(folder,pulseInfo_name)
%USAGE fit_pulse_model_multi(folder,pulseInfo_name)
%e.g.
%fit_pulse_model_multi('/Users/sternd/Documents/Projects/courtship_song_analysis.w.t.-forpaper/WT_species/mel-all-6Mar/','culled_pulseInfo')
%
%pulseInfo_name can take 'pulseInfo', 'pulseInfo2', 'culled_pulseInfo',etc.
%If enter 'culled_pulseInfo', then model and Lik are saved with new name
%(with prefix 'culled_'
pI_name = char(pulseInfo_name);
if strncmp(pulseInfo_name,'culled_',7)
culled = 1;
else
culled = 0;
end
if strcmp(folder(end),'/') == 0
folder = [folder '/'];
end
dir_list = dir(folder);
file_num = length(dir_list);
for y = 1:file_num
file = dir_list(y).name; %pull out the file name
[~,root,ext] = fileparts(file);
path_file = [folder file];
TG = strcmp(ext,'.mat');
if TG == 1
W = who('-file',path_file);
varstruc =struct;
load(path_file);
for ii = 1:numel(W)
varstruc.(W{ii}) = eval(W{ii});
end
% pIData = load(path_file,pI_name);
pI_data = varstruc.(pI_name);
[pM,Lp] = fit_pulse_model(pI_data.x);
if culled == 1
varstruc.culled_pulse_model = pM;
varstruc.culled_Lik_pulse = Lp;
varstruc.culled_pulse_model.variables.pulseInfo_ver = pI_name;
varstruc.culled_pulse_model.variables.date = date;
varstruc.culled_pulse_model.variables.time = clock;
varstruc.culled_Lik_pulse.variables.pulseInfo_ver = pI_name;
varstruc.culled_Lik_pulse.variables.date = date;
varstruc.culled_Lik_pulse.variables.time = clock;
elseif culled == 0
varstruc.pulse_model = pM;
varstruc.Lik_pulse = Lp;
varstruc.pulse_model.variables.pulseInfo_ver = pI_name;
varstruc.pulse_model.variables.date = date;
varstruc.pulse_model.variables.time = clock;
varstruc.Lik_pulse.variables.pulseInfo_ver = pI_name;
varstruc.Lik_pulse.variables.date = date;
varstruc.Lik_pulse.variables.time = clock;
end
save(path_file,'-struct','varstruc','-mat')%save all variables in original file
end
end