load fish10000.mat

bspike = rho; %input is a binary vector, 1 ms bins
stimulus = stim;
n = 400; % number of .5 ms time steps to go back

bspike(1:n-1) = 0;    % discard spikes occuring prior to n ms
spiketimes = find(bspike >0); %make a vector of all the spike times (in ms)


for i = 0:n-1
    
    shift = spiketimes-i; %all the times i 1/2 ms shifted back from the spike times
    STA(i+1) = mean(stim(shift)); % mean value of the stimulus at the shifted times
    
end


STAplot = fliplr(STA); %flip the STA vector so we can show it from past to future

tvec = -((n/2)-.5):.5:0; % calculate the appropriate time vector

plot(tvec,STAplot) %make the plot