-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLFP_NEXfile.m
120 lines (100 loc) · 3.48 KB
/
LFP_NEXfile.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function LFPstruct=LFP_NEXfile(dirName,outDir)
% function LFP_NEXfile(dirName,outDir)
% extracts only LFP data from a nex file, asks you which nex file you want
% to use.
% Extract LFP traces
% First I have to turn all my lfps into nex files.
% once I get the nex files, I have to reconstitute the timestamps and match
% them with the traces. Then im probably going to have to find the best
% LFP from the dataset. I think i'll also have to restrict my dataset to
% the first two jumpers (max tetrode is 61) because alot of the MEC
% recordings also have RSP, and LEC recordings have PER
if ~exist('dirName','var')
dirName=uigetdir('','Choose Directory of NEX files');
elseif isempty(dirName)
dirName=uigetdir('','Choose Directory of NEX files');
end
if ~exist('outDir','var')
outDir=uigetdir('','Choose a Save Directory');
elseif isempty(dirName)
outDir=uigetdir('','Choose a Save Directory');
end
dash=WhichDash;
dirData=dir(dirName);
fileNames={dirData(~[dirData.isdir]).name}';
fileList=cellfun(@(a) fullfile(dirName,a), fileNames,'UniformOutput',false);
choose=0;
% so you can choose multiple files
if choose==1
if length(fileNames)<20
checked=checkBox(fileNames);
else
checked1=checkBox(fileNames(1:20));
check ed2=checkBox(fileNames(21:end));
checked=[checked1 checked2+20];
end
else
checked=ones(length(fileNames),1);
end
% now go through all files and find your LFP
for j=1:length(fileList)
if checked(j)==1
nex=readNexFileM(fileList{j});
allfields=fieldnames(nex);
% look for my contvars
% get all the contvars
LFPfield=strcmp(allfields,'contvars');
if any(LFPfield)
allLFPs=nex.(allfields{LFPfield});
end
% ditch the strobe and non lfp channels
keeplfp=[];
for i=1:length(allLFPs)
keeplfp(i)=any(strfind(allLFPs{i}.name,'F'));
end
allLFPs=allLFPs(logical(keeplfp));
% now we can go after real lfps:
% for first ten
figure
q=0;
% label and plot all the lfps
for i=1:min([10 length(allLFPs)]);
q=q+1;
subplot(5,2,i);
plot(allLFPs{i}.data(10000:50000));
title(['lfp ' num2str(i) ' of ' num2str(length(allLFPs))]);
end
linkaxes;
ylim([-.7 .7]);
% if you want to choose a single LFP for this session
chooselfp=0;
if chooselfp
% choose, if you dont choose go for next ten
bestlfp=input('Choose the best lfp number (1:10): ');
close
if isempty(bestlfp)
figure
for i=1:10
q=q+1;
subplot(5,2,i);
plot(allLFPs{q}.data(10000:50000));
title(['lfp ' num2str(q) ' of ' num2str(length(allLFPs))]);
end
linkaxes;
ylim([-.7 .7]);
bestlfp=input('Choose the best lfp number (11:20): ');
end
fprintf('\n');
if ~isempty(bestlfp)
LFPstruct=allLFPs{bestlfp};
save([outDir dash fileNames{j}(1:end-4) '_LFP'],'LFPstruct');
close
fprintf(['saved in ' outDir]);
else
fprintf('you didnt choose, so nothing saved \n');
end
else
LFPstruct=allLFPs;
end
end
end