close all
clear all
clc

tic

% save one channel per file and create a reference polytrode1.txt file with 
%the names of channel files
FName = 'RA_16ch_25kHz_1min';
SelectedChannels = 6:9; %the largest neuron is in ch#8
%SelectedChannels = 5:10; %the largest neuron is in ch#8
load([FName '.mat']);
MyData = -data(SelectedChannels,:);    
       %"-" because in waveclust is assumed that spikes go upwards
nbchan = size(MyData,1);
clear data;

TextFileName = strcat('polytrode',num2str(1),'.txt');
fileID = fopen(TextFileName, 'w');

 for i=1:nbchan
    data=double(MyData(i,:));   %for some reason 'single' can give an error later
    FNameN = [FName '_ch' num2str(SelectedChannels(i)) '.mat'];
     save(FNameN,'data')    
     fprintf(fileID,'%s\n',FNameN);
 end
 
fclose(fileID);
 
toc   % 2.949185 seconds for four channels
