clear;
load miniDB;

subset.amplitude = amplitude(decay>12);
subset.area = area(decay>12);
subset.bath = bath(decay>12);
subset.culture = culture(decay>12);
subset.decay = decay(decay>12);
subset.div = div(decay>12);
subset.fid = fid(decay>12);
subset.rise = rise(decay>12);
subset.time = time(decay>12);
subset.treatment = treatment(decay>12);


fid_tmp = unique(subset.fid);
for j = 1:length(fid_tmp)
    ind = strfind(fid_tmp{j},'_');
    j
    if numel(ind)>=2
        fidlist{j} = fid_tmp{j}(1:ind(2)-1);
    else
        fidlist{j} = fid_tmp{j};
    end
end
fidlist = unique(fidlist);


close all; figure; subplot(2,1,1)
for i = 1:length(fidlist)
    %keyboard;
    amp_tmp = subset.amplitude(strmatch(fidlist{i},subset.fid));
    amp_tmp = amp_tmp(amp_tmp<200);
    tre_tmp = subset.treatment(strmatch(fidlist{i},subset.fid));
    tre_tmp = unique(tre_tmp);
    switch char(tre_tmp)
        case 'CNQX'
            col = [1 0 0];
        case 'TTX'
            col = [0 0.5 1];
        case 'control'
            col = [0 0 0];
        otherwise
            col = [0.5 0.5 0.5];
    end
    plot(ones(size(amp_tmp))*i*0.01+0.001*randn(size(amp_tmp)),amp_tmp,'.','MarkerSize',4,'Color',col);
    hold on;
    %ind = strfind(fidlist{i},'_');
    %fidlabel{i} = fidlist{i}(1:ind(1)-1);
    fidlabel{i,1} = [char(unique(subset.culture(strmatch(fidlist{i},subset.fid)))) ' (' num2str(0.01*round(100*mean(amp_tmp))) ' +/- ' num2str(0.01*round(100*std(amp_tmp))) 'pA, n=' num2str(length(amp_tmp)) ')'];
end


axis([0 (i+1)*0.01 0 150]);
set(gca,'TickLength',[0.002 0.002]);
set(gca,'XTick',[1:length(fidlist)]*0.01,'XTickLabel',fidlabel,'FontSize',14);
rotateticklabel(gca,90);
%xlabel('cell');
ylabel('mEPSC amplitude (pA)','FontSize',10);
