Hi everyone,

I’m a beginner for neuronal spiking analysis.

I’m studying for that by reading Mike’s “MATLAB for Brain and Cognitive Scientists.” and that’s a very excellent book!

Now I’m struggling with autocorrelation.

In chapter 23 of that book, I don’t come up with a line of code at the part of the following code “**in the % need an extra line of code here…**”

I understand there’s a problem in index of “spikes(si)-win:spikes(si)+win” because some indices have negative values.

Somebody help me with that?

In addition, what about using Matlab function xcorr for autocorrelation or cross corelation analysis? Any problems?

Thank you in advance.

Best,

Hideki

%% spike timing with full matrices

win = 50; % in ms and also in indices (only in this dataset!)

spikerhyth = zeros(1,win*2+1);

n = 0;

for triali=1:trialnum

```
spikes = find(spikesfull(triali,:));
% need an extra line of code here...
for si=1:length(spikes)
spikerhyth = spikerhyth + spikesfull(triali,spikes(si)-win:spikes(si)+win);
n = n+1;
end % end spike loop
```

end % end trial loop

% divide by N to finalize average

spikerhyth = spikerhyth./n;

figure(2), clf

plot(-win:win,spikerhyth,‘rs-’)

set(gca,‘xlim’,[-10 10])