Skip to content

Commit 912c786

Browse files
committed
Working (I think) copy of error trials code and also basic attempts at plotting
1 parent fc34049 commit 912c786

File tree

2 files changed

+68
-47
lines changed

2 files changed

+68
-47
lines changed

code/dataexample.m

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
% Load the file and
22

33
filename = 'C:/Users/Felicity/macaqueERP/data/epocheddata.mat';
4-
d = load(filename);
4+
errorfilename = 'C:/Users/Felicity/macaqueERP/data/errordata.mat';
5+
norm = load(filename);
6+
error = load(errorfilename);
57

6-
electrode = 1;
7-
trial = 4;
8+
electrode = round(input('Which electrode? (1-14)\n'));
89

10+
normdata = norm.data{1,1}.odd;
11+
errordata = error.data{1,1}.noleverresponse;
12+
xdata = norm.data{1,1}.xaxis;
913

10-
exampledata = d.data{1,1};
11-
12-
xdata = exampledata.xaxis;
13-
ydata = squeeze(exampledata.odd(electrode,trial,:));
14-
15-
16-
meanydata = squeeze(mean(exampledata.odd(electrode,:,:),2));
17-
14+
normmeanydata = squeeze(mean(normdata(electrode,:,:),2));
15+
errormeanydata = squeeze(mean(errordata(electrode,:,:),2));
16+
plot(xdata,normmeanydata)
1817
hold on
19-
plot(xdata,meanydata)
18+
plot(xdata, errormeanydata)
2019
xlabel('Time (s)')
2120
ylabel('Voltage (\muV)')
2221

23-
2422
disp('Done.')

code/errortrials.m

+57-34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% THe basic idea was to base the code off of the categorizetrials.m file, but make a few
1+
% The basic idea was to base the code off of the categorizetrials.m file, but make a few
22
% adjustments to pull at error trials. The types of errors was split into 2 types: the monkey
33
% pulling the lever for no reason, and the monkey failing to respond to the odd stimulus of the
44
% specified type. Using the same structure as categorizetrials.m, the data was stored the stimcount
@@ -9,8 +9,8 @@
99

1010
datadir = 'C:/Users/Felicity/macaqueERP/data/raw/R7475/';
1111
addpath(datadir) % So X_loadcnt() is available
12-
outfile='tmp.mat'; % Output filename
13-
dosave = 0; % Whether or not to save
12+
outfile='C:/Users/Felicity/macaqueERP/data/errordata.mat'; % Output filename
13+
dosave = 1; % Whether or not to save
1414
oldrate=2000; % Sampling rate in Hz
1515
epochstart=-0.2; % Start of epoch in s
1616
epochend=0.4; % End of epoch in s
@@ -25,11 +25,11 @@
2525
%% 1. Loading data
2626

2727
allfiles=dir([datadir '*.cnt']); % Get all file names
28-
% nfiles=length(allfiles);
29-
nfiles = 1;
28+
nfiles=length(allfiles);
29+
% nfiles = 1;
3030

3131

32-
for Z=1:1 % Loop over files (stay as 1 just for error checking)
32+
for Z=1:nfiles % Loop over files (stay as 1 just for error checking)
3333
fprintf('\nLoading file %i of %i (%s)...\n',Z,nfiles,allfiles(Z).name)
3434
tmpdata=X_loadcnt(allfiles(Z).name);
3535
origdata=tmpdata.data'; % Pull out the interesting array and transpose it
@@ -40,56 +40,56 @@
4040
xaxis=(0:length(origdata)-1)/oldrate; % Set up an x-axis to plot everything
4141

4242
labels={'Auditory target (green: lever)','Visual target (green: lever)'};
43-
levertimes=diff(origdata(:,61)); levertimes=find(levertimes>200)/oldrate; % Pull out lever times
43+
levertimes=diff(origdata(:,61)); levertimes=find(levertimes>200); % Pull out lever times
4444
npulls=length(levertimes); % How many times the monkey pulled the lever
45-
audodd=diff(origdata(:,58)); audodd=find(audodd<-200)/oldrate; % Pull out auditory oddball stimuli
46-
visodd=diff(origdata(:,60)); visodd=find(visodd<-200)/oldrate; % Pull out visual oddball stimuli
45+
audodd=diff(origdata(:,58)); audodd=find(audodd<-200); % Pull out auditory oddball stimuli
46+
visodd=diff(origdata(:,60)); visodd=find(visodd<-200); % Pull out visual oddball stimuli
4747
audpositive=0;
4848
vispositive=0;
4949

5050

5151
% Time to find the errors
5252

5353
% First, find the errors for using the lever for no reason.
54-
errorlevertimes = zeros(50, 1); % store the times in row vector
55-
levercounting = 0 % to get the position in vector (also count errors)
54+
errorlevertimes = zeros(1, 30); % store the times in row vector
55+
levercounting = 0; % to get the position in vector (also count errors)
5656

5757
for i=1:length(levertimes)
5858
tmpaud=levertimes(i)-audodd; % Find the time difference between the lever press and the stimuli
5959
tmpvis=levertimes(i)-visodd; % Find the time difference between the lever press and the stimuli
60-
tmpaud=tmpaud(tmpaud>0.05 & tmpaud<1.2); % Give it between 100 ms and 1 s to respond
61-
tmpvis=tmpvis(tmpvis>0.05 & tmpvis<1.2); % Give it between 100 ms and 1 s to respond
60+
tmpaud=tmpaud(tmpaud>0.05*oldrate & tmpaud<1.2*oldrate); % Give it between 100 ms and 1 s to respond
61+
tmpvis=tmpvis(tmpvis>0.05*oldrate & tmpvis<1.2*oldrate); % Give it between 100 ms and 1 s to respond
6262

6363
if isempty(tmpvis)&&isempty(tmpaud)
6464
levercounting = levercounting + 1;
65-
errorlevertimes(levercounting) = levertimes(i);
65+
errorlevertimes(1, levercounting) = levertimes(i);
6666
end
6767
end
6868
fprintf('%d errors for pulling lever for no reason\n', levercounting)
6969

7070

7171
% Next, find the errors (assuming audio-attend) for not responding to odd auditory stimulus
7272
audcounting = 0;
73-
erroraudtimes = zeros(50, 1);
73+
erroraudtimes = zeros(1, 30);
7474
for i = 1:length(audodd)
7575
diffaud = levertimes-audodd(i);
76-
diffaud = diffaud(diffaud>0.05 & diffaud<1.2);
76+
diffaud = diffaud(diffaud>0.05*oldrate & diffaud<1.2*oldrate);
7777
if isempty(diffaud)
7878
audcounting = audcounting + 1;
79-
erroraudtimes(audcounting) = audodd(i);
79+
erroraudtimes(1, audcounting) = audodd(i);
8080
end
8181
end
8282

8383

8484
% Then, find the errors (assuming visual-attend) for not responding to odd visual stimulus
8585
viscounting = 0;
86-
errorvistimes = zeros(500, 1);
86+
errorvistimes = zeros(1, 30);
8787
for i = 1:length(visodd)
8888
diffvis = levertimes-visodd(i);
89-
diffvis = diffvis(diffvis>0.05 & diffvis<1.2);
89+
diffvis = diffvis(diffvis>0.05*oldrate & diffvis<1.2*oldrate);
9090
if isempty(diffvis)
9191
viscounting = viscounting + 1;
92-
errorvistimes(viscounting) = visodd(i);
92+
errorvistimes(1, viscounting) = visodd(i);
9393
end
9494
end
9595

@@ -99,25 +99,25 @@
9999
if viscounting > audcounting
100100
fprintf('%d errors for failing to respond to odd auditory stimulus\n', audcounting);
101101

102-
A = 1 % A= 1 means we are attending audio
103-
errortimes = [errorlevertimes; erroraudtimes]
102+
A = 1; % A= 1 means we are attending audio
103+
errortimes = [errorlevertimes; erroraudtimes];
104104
elseif audcounting > viscounting
105105
fprintf('%d errors for failing to respond to odd visual stimulus\n', viscounting);
106-
A = 2 % A= 2 means we are attending visual
107-
errortimes = [errorlevertimes; errorvistimes]
106+
A = 2; % A= 2 means we are attending visual
107+
errortimes = [errorlevertimes; errorvistimes];
108108

109109
else
110110
disp('Monkey confused about which stimulus to attend to\n');
111111
A=input('Auditory (1) or visual (2)? ');
112112
if A == 1
113-
errortimes = [errorlevertimes; erroraudtimes]
113+
errortimes = [errorlevertimes; erroraudtimes];
114114
fprintf('%d errors for failing to respond to odd auditory stimulus\n', audcounting);
115115
else
116-
errortimes = [errorlevertimes; errorvistimes]
116+
errortimes = [errorlevertimes; errorvistimes];
117117
fprintf('%d errors for failing to respond to odd visual stimulus\n', viscounting);
118118
end
119119
end
120-
120+
121121
% Now begin to collate the data into a nice structure thing
122122

123123
for Q=1:2 % Loop over V4 vs. IT
@@ -142,7 +142,7 @@
142142
end
143143

144144
%% 3. Split the data up into trials
145-
trialtypes={'no stimulus','no lever reponse'}; % Trial types -- audio no stim, audio no response, visno stim , vis no response
145+
trialtypes={'nostimulus','noleverresponse'}; % Trial types -- audio no stim, audio no response, visno stim , vis no response
146146
ntypes=length(trialtypes);
147147
nchannels=length(channels);
148148
npts=ceil((epochend-epochstart)*newrate); % Number of points in each trial window
@@ -160,26 +160,49 @@
160160
% totalpts=length(thisstim); % Total number of data points
161161
% stimdiff=diff(thisstim); % Detect changes in the stimuli
162162
% stimtimes=find(stimdiff<-200); % Changes are huge decreases (~-500) in the stim time series
163-
totalpts = length(xaxis)
164-
stimtimes = errortimes(i)
163+
totalpts = length(origdata(:, 57));
164+
stimtimes = errortimes(i, :);
165+
165166
stimtimes=stimtimes(stimtimes>oldptsbefore & stimtimes<(totalpts-oldptsafter)); % Remove stimuli that are too close to the beginning or end of the recording
167+
stimtimes = stimtimes(stimtimes ~=0);
166168
nstims=length(stimtimes); % Number of stimuli
167-
168169
% Set up the array to store results in
169170
if Z==1, data{A,Q}.(trialtypes{i})=zeros(nchannels,3000,npts); end % Set up array if not set up before, 3000 is arbitrary to make it big enough
170171

171172
% Pull out the corresponding data
172173
for j=1:nchannels
173174
for k=1:nstims
174175
stimcount(A,Q,i,j)=stimcount(A,Q,i,j)+1; % Total number of stimuli -- sum over files (Z) and k but nothing else
175-
thisdata=origdata(stimtimes(k)*oldrate-oldptsbefore:stimtimes(k)*oldrate+oldptsafter+oldrate/newrate,channels(Q,j));
176+
thisdata=origdata(stimtimes(k)-oldptsbefore:stimtimes(k)+oldptsafter,channels(Q,j));
176177
% Pull out the data; oldrate/newrate is to give one extra data point. Also need to *stimtimes by old rate to get correct numbers
177-
tmp=downsample(thisdata,oldrate,newrate); % Downsample to the desired rate
178+
179+
tmp=downsample(thisdata,oldrate/newrate); % Downsample to the desired rate
178180
data{A,Q}.(trialtypes{i})(j,stimcount(A,Q,i,j),:)=tmp; % Append to entire array
179181
end
180182
end
181183
end
182184
end
183185
end
184186

185-
disp('Done');
187+
for A=1:2
188+
for Q=1:2
189+
for i=1:ntypes
190+
data{A,Q}.(trialtypes{i})=data{A,Q}.(trialtypes{i})(:,1:stimcount(A,Q,i,1),:); % Trim extra "rows"
191+
end
192+
end
193+
end
194+
195+
if dosave
196+
fprintf('\nSaving data...\n')
197+
save(outfile,'data') % Save data
198+
disp('...done.')
199+
end
200+
201+
% checkplot = data{2,1};
202+
% xdata = checkplot.xaxis;
203+
% meanydata = squeeze(mean(checkplot.noleverresponse(2,1,:),2));
204+
% plot(xdata,meanydata)
205+
% xlabel('Time (s)')
206+
% ylabel('Voltage (\muV)')
207+
%
208+
% disp('Done');

0 commit comments

Comments
 (0)