So I have this matrix NxM size. Each row represents a spiking pattern of a neuron in one time frame. Each row which has 0s or 1s, i.e. spikes, is followed by 2 rows with all 0s.
I want to find the average firing rate per x milliseconds time bin, which is, say Y points in the 2nd dimension. Now if I run a loop like this -
avg_rate = ;
for i = 1:bin:size(spikes_21)-bin
avg1 = mean(spikes_21(:,i:i+bin-1),1);
avg_rate = [avg_rate avg1];
I will end up with a much lower average because even the 0s will be added up and averaged.
I could count the number of rows with non-zero elements, sum up each bin and divide by the number of valid rows. But that'll take another loop and I'm already processing 32 channels and each channel takes 40 mins to run, and then this process is to be done for the 21st channel. So it'll be extremely long.
Is there a simpler way to do this?