-
Notifications
You must be signed in to change notification settings - Fork 14
/
Spk2txt.m
63 lines (52 loc) · 1.73 KB
/
Spk2txt.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
function Spk2txt(filename,chn)
%test file
%filename='H30L6A0_15050';
if nargin<2
%specify which channel was exported from Spike2
chn=6;
end
%load data from file
try
load([filename '_Ch' num2str(chn,'%d')],'-mat');
catch wrongdir
dir='E:\Data\WaveSorter\';
load([dir filename '_Ch' num2str(chn,'%d')],'-mat');
end
%copy data into new variable named data
eval(['data = ' filename '_Ch' num2str(chn,'%d')]);
%remove old variable from memory
vars=who;
evalin('base',['clear ',cell2mat(vars(~cellfun('isempty',regexp(who,filename))))]);
clear vars;
%adjust voltage traces toward positiveness and, if needed, resample
data.values=data.values+ceil(abs(min(min(data.values)))*100)/100;
rsvals=data.values; %no resampling. For resampling to keep 25 values: (resample((data.values)',25,size(data.values,2)))';
%build matrix of data to export. column 1: electrode number, column 2: time stamp, column 3: voltage value
% datexport=[zeros(size(data.times))...
% round(data.times*50000)...
% rsvals];
%print header for WaveSorter
txtfilename = [filename '.txt'];
fid = fopen(txtfilename, 'w');
fprintf(fid, '%d\t%d\tet\n',size(rsvals,1),size(rsvals,2));
eno = 0;
data.times = round(data.times.*50000);
for a = 1:size(rsvals,1)
newrow = [];
for b = 1:size(rsvals,2)
if (b == size(rsvals,2))
newrow = [newrow sprintf('%7.7f',rsvals(a,b))];
else
newrow = [newrow sprintf('%7.7f\t',rsvals(a,b))];
end
end
if a == size(rsvals,1)
fprintf(fid, ['%d\t%d\t' newrow],eno,data.times(a));
else
fprintf(fid, ['%d\t%d\t' newrow '\n'],eno,data.times(a));
end
end
fclose(fid);
%print data proper
%dlmwrite(txtfilename, datexport, '-append', 'delimiter', '\t', 'precision', 8)
end