dirID = 'G:\ming\2013-01-26_vivy21369_10-13DIV_6well\';
fid = 'vivy21369_10DIV_nodrug_02';
x1 = loadspk([dirID fid '.spk']);

fid = 'vivy21369_11DIV_drugs_01';
x2 = loadspk([dirID fid '.spk']);

fid = 'vivy21369_12DIV_wash4_01';
x3 = loadspk([dirID fid '.spk']);

time = [x1.time-max(x1.time); x2.time(x2.time<24*3600); x3.time+24*3600];
channel = [x1.channel; x2.channel(x2.time<24*3600); x3.channel];
unit = [x1.unit; x2.unit(x2.time<24*3600); x3.unit];
threshold = [x1.threshold; x2.threshold(x2.time<24*3600); x3.threshold];
waveform = [x1.waveform x2.waveform(:,(x2.time<24*3600)) x3.waveform];

%save([dirID 'vivy21367_10-12DIV.mat'],'time','channel','unit','threshold');
save([dirID 'vivy21369_10-12DIV_waveform.mat'],'time','channel','threshold','unit','waveform','-v7.3');

%%
clear x*
x.time = time;
x.channel = channel;
x.unit = unit;
x.threshold = threshold;
x.waveform = waveform;


%%
excludechannels = [1 6 8 11 32 33 54 57 59 64];
w(1,:) = [3 4 5 12 13 20 21 28 29];
w(2,:) = [7 14 15 16 22 23 24 30 31];
w(3,:) = [38 39 40 46 47 48 55 56 63];
w(4,:) = [36 37 44 45 52 53 60 61 62];
w(5,:) = [34 35 41 42 43 49 50 51 58];
w(6,:) = [2 9 10 17 18 19 25 26 27];
excludechannels = horzcat(excludechannels,w(1,:),w(2,:),w(3,:),w(4,:),w(5,:));

ind = find(ismember(x.channel,excludechannels)==0);
time = x.time(ind);
channel = x.channel(ind);
unit = x.unit(ind);
threshold = x.threshold(ind);
waveform = x.waveform(:,ind);

save vivy21369F_10-12DIV_waveform threshold time channel waveform unit


%%
clear all;
fid = 'vivy21369D_10-12DIV';
spkdat = load([fid '_waveform.mat']);
SS = SqueakySpk([fid '_DoublePeakSortNR'],25000,1,spkdat);
SS.Save;
