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

fpath = 'C:\Users\USER\Documents\mingfaifong_tmp\2011.04.22 Two-day Chronic AMPAR Blockade (Turbo)\turbo361\';
fpath_info = dir(fpath);      %get info about contents of directory
isfile = ~[fpath_info.isdir]; %get index for files only
fidlist = {fpath_info(isfile).name}; %create list of files

for i = 1:length(fidlist)

    clearvars -except i fidlist T0 fpath channel time threshold waveform
    fid = fidlist{i};

    %determine time at beginning of file based on location of dashes in filename
    dashloc = strfind(fid,'-');
    T = [str2double(fid(dashloc(length(dashloc)-5)+1:dashloc(length(dashloc)-4)-1)),... %year
        str2double(fid(dashloc(length(dashloc)-4)+1:dashloc(length(dashloc)-3)-1)),... %month
        str2double(fid(dashloc(length(dashloc)-3)+1:dashloc(length(dashloc)-2)-1)),... %day
        str2double(fid(dashloc(length(dashloc)-2)+1:dashloc(length(dashloc)-1)-1)),... %hour
        str2double(fid(dashloc(length(dashloc)-1)+1:dashloc(length(dashloc))-1)),... %minute
        str2double(fid(dashloc(length(dashloc))+1:length(fid)-4))]; %second

    %set T0 as time of first file
    if i == 1
        T0 = T;
    end

    %load spike file and adjust time
    x = loadspike([fpath fid]);
    starttime = etime(T,T0);
    x.time = x.time+starttime;
    
    %update arrays
    channel = [channel; x.channel];
    time = [time; x.time];
    threshold = [threshold; x.threshold];
    
    waveform = [waveform, x.waveform];

end

fid_prefix = fid(1:dashloc(length(dashloc)-5)-1);
save([fid_prefix '_nowaveform.mat'],'channel','time','threshold','waveform');