-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv2struct.m
69 lines (51 loc) · 1.66 KB
/
csv2struct.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
function [data,electrode] = csv2struct(filename)
% load in the csv file
% electrode names
count =0;
ename = {};
xval={'A' ;'B'; 'C'; 'D'; 'E'; 'F'};
for i=1:length(xval)
for j=0:9
count = count+1;
eName{count} = sprintf('%s0%d',xval{i},j);
end
end
[a,b,c] = xlsread(filename);
electrodeCol = find(strcmp('PTS_Electrodes',b(1,:)));
ampCol = find(strcmp('PTS_Amplitude',b(1,:)));
respCol = find(strcmp('KEY',b(1,:)));
trialCol = find(strcmp('Trial No.',b(1,:)));
subjectCol = find(strcmp('subject_id',b(1,:)));
electrodesUsed = unique(c(3:end,electrodeCol));
data.subject = c{2,subjectCol};
for i=1:size(c,1)
trialNum = c{i,trialCol};
if ~isempty(trialNum) && ~ischar(trialNum) && ~isnan(trialNum)
curElectrode = c{i,electrodeCol};
if strcmp(curElectrode,'none')
data.electrodeNum(trialNum)=0;
data.amp(trialNum) = 0; % amplitude is zero for a catch trial
else
data.electrodeNum(trialNum) = find(strcmp(eName,curElectrode));
data.amp(trialNum) = c{i,ampCol};
end
resp = c{i,respCol};
switch resp
case 'Y'
data.resp(trialNum) = 1;
case 'N'
data.resp(trialNum) = 0;
end
end
end
for i=1:length(eName)
electrode.x(i) = find(strcmp(eName{i}(1),xval));
electrode.y(i) = str2num(eName{i}(2:end));
end
% Calculate P(yes | catch trial)
electrode.pCatch = mean(data.resp(data.electrodeNum==0));
electrode.pThresh = .5;
electrode.pLapse = 0;
[electrode.xPlot,electrode.yPlot] = meshgrid(0:.5:(max(electrode.x)+1),0:.5:(max(electrode.y)+1));
data.x = electrode.x;
data.y = electrode.y;