%% plot amplitudes

clear all; close all;
load worm_alldata

n_cutoff = 30;
n_firstCTZ = 10;

figure(1); hold off;

for i = 1:length(dat)
    tmp_amp = dat{i}(:,5);
    subplot(2,1,1);
    h = plot(i*ones(size(tmp_amp))+0.15*randn(size(tmp_amp)),tmp_amp,'.k');
    hold on;
    if i >= n_firstCTZ
        set(h,'Color','r');
    end
    amp.mean(i) = nanmean(tmp_amp);
    amp.n(i) = length(tmp_amp);
    amp.stderr(i) = std(tmp_amp)/sqrt(amp.n(i));
    disp([fidlist{i},': ',num2str(amp.mean(i)),' +/- ', ...
        num2str(amp.stderr(i)), ' pA', ...
        '   (n=',num2str(amp.n(i)),')']);
end
ylabel('Decay Time (ms)','FontSize',14);

ampMean(:,1) = amp.mean;
ampMean(:,2) = amp.stderr;

subplot(2,1,2); hold off;
errorbar(1:n_firstCTZ-1,ampMean(1:n_firstCTZ-1,1),ampMean(1:n_firstCTZ-1,2),'ko'); hold on;
errorbar(n_firstCTZ:size(ampMean,1),ampMean(n_firstCTZ:end,1),ampMean(n_firstCTZ:end,2),'ro');


ampMean_cutoff(:,1) = amp.mean(amp.n>=n_cutoff);
ampMean_cutoff(:,2) = amp.stderr(amp.n>=n_cutoff);
n_CTZ_inc = 1;

subplot(2,1,1);
plot([0.5,size(ampMean,1)+0.5],[mean(ampMean_cutoff(1:n_firstCTZ-1-n_CTZ_inc,1)) mean(ampMean_cutoff(1:n_firstCTZ-1-n_CTZ_inc,1))],'k--');
plot([0.5,size(ampMean,1)+0.5],[mean(ampMean_cutoff(n_firstCTZ-n_CTZ_inc:end,1)) mean(ampMean_cutoff(n_firstCTZ-n_CTZ_inc:end,1))],'r--');

subplot(2,1,2);
plot([0.5,size(ampMean,1)+0.5],[mean(ampMean_cutoff(1:n_firstCTZ-1-n_CTZ_inc,1)) mean(ampMean_cutoff(1:n_firstCTZ-1-n_CTZ_inc,1))],'k--');
plot([0.5,size(ampMean,1)+0.5],[mean(ampMean_cutoff(n_firstCTZ-n_CTZ_inc:end,1)) mean(ampMean_cutoff(n_firstCTZ-n_CTZ_inc:end,1))],'r--');

ylabel('Decay Time (ms)','FontSize',14);

