clear;

badchan = [1 8 33 57 64];
fpath = 'C:\Users\USER\Documents\mingfaifong\gatsby363\matfiles\suspiciously large files\';
spath = 'C:\Users\USER\Documents\mingfaifong\gatsby363\matfiles\';
fid = 'gatsby363_101to102hr.mat';

inc = 10; %in seconds
t_inc = 0:inc:0.5*3600;

channel = [];
time = [];
threshold = [];
waveform = [];

T0 = clock;
for i = 1:length(t_inc)-1
    x = load([fpath fid]);
    ind_goodchan = find(x.channel~=badchan(1) & x.channel~=badchan(2));
    x.time = x.time(ind_goodchan);
    x.channel = x.channel(ind_goodchan);
    x.waveform = x.waveform(:,ind_goodchan);
    x.threshold = x.threshold(ind_goodchan);
    time = [time; x.time];
    channel = [channel; x.channel];
    waveform = [waveform, x.waveform];
    threshold = [threshold; x.threshold];
    %keyboard;
    clear x;
end
T1 = clock;
etime(T1,T0)

save([spath fid(1:length(fid)-4) '.mat'],'time','channel','waveform','threshold');