%% Spike rate computed for all trials

display('To compute the mean spike rate for all trials, press return');
pause
%
% Pool data from all trials into 1 column vector
%
data1=[];
for n=1:Ntrials;
    data1=[data1; dsp1t(n).times];
end;
data2=[];
for n=1:Ntrials;
    data2=[data2; dsp2t(n).times];
end;
%
% Compute the fits
%
nn=0.3;
fit1t=locfit(data1,'family','rate','nn',nn);
xlim=[min(data2) max(data2)];
fit2t=locfit(data2,'family','rate','nn',nn);
%
% Call the plotting function
figure;
subplot(211); plot_ratealltrials(dsp1t,fit1t);
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('time s'); ylabel('Rate Hz');
title('Cell 1');
subplot(212); plot_locfit(dsp2t,fit2t);
set(gca,'FontName','Times New Roman','Fontsize', 16);
xlabel('time s'); ylabel('Rate Hz');
title('Cell 2');
position_figure