clear all; close all;

n_cutoff = 30;
%bootstrap = 0;

feature = 'amplitude';
% -- setting values for feature of interest -- %
switch feature
    case 'amplitude'
        f_label = 'Amplitude';
        f_unit = 'pA';
        f_datcol = 3;
        f_bounds = [5 400];
        f_cumhist = 1;
    case 'frequency'
        f_label = 'Frequency';
        f_unit = 'Hz';
        f_datcol = 19;
        f_bounds = [1/200 1000];
        f_cumhist = 0;
    case 'decay'
        f_label = 'Decay Time Constant';
        f_unit = 'ms';
        f_datcol = 5;
        f_bounds = [0.2 6]; %for AMPAergic minis
        f_cumhist = 0;
    case 'charge'
        f_label = 'Charge Transfer';
        f_unit = 'fC';
        f_datcol = 6;
        f_bounds = [1 inf];
        f_cumhist = 0;
end


load('C:\Users\mingfaifong\Documents\2013-03-12_CNQX-stim1x-vehicle_patch-analysis\ctrl_CNQX_CNQXstim1x_cellsByTreatment.mat')

i_goodCellNum = 1;
for i_cellNum = 1:length(ctrl)
    if size(ctrl{i_cellNum},1) < n_cutoff
        continue
    end
    x = ctrl{i_cellNum,1}(:,f_datcol);
    x = x(x>=f_bounds(1) & x<=f_bounds(2));
    avg.byCell.ctrl.value(i_goodCellNum,1) = nanmean(x);
    avg.byCell.ctrl.cultureSeries(i_goodCellNum,1) = ctrl(i_cellNum,2);
    avg.byCell.ctrl.std(i_goodCellNum,1) = nanstd(x);
    avg.byCell.ctrl.n(i_goodCellNum,1) = length(x);
    i_goodCellNum = i_goodCellNum+1;
end    

i_goodCellNum = 1;
for i_cellNum = 1:length(CNQX)
    if size(CNQX{i_cellNum},1) < n_cutoff
        continue
    end
    x = CNQX{i_cellNum,1}(:,f_datcol);
    x = x(x>=f_bounds(1) & x<=f_bounds(2));
    avg.byCell.CNQX.value(i_goodCellNum,1) = nanmean(x);
    avg.byCell.CNQX.cultureSeries(i_goodCellNum,1) = CNQX(i_cellNum,2);
    avg.byCell.CNQX.std(i_goodCellNum,1) = nanstd(x);
    avg.byCell.CNQX.n(i_goodCellNum,1) = length(x);
    i_goodCellNum = i_goodCellNum+1;
end    

i_goodCellNum = 1;
for i_cellNum = 1:length(CNQXstim1x)
    if size(CNQXstim1x{i_cellNum},1) < n_cutoff
        continue
    end
    x = CNQXstim1x{i_cellNum,1}(:,f_datcol);
    x = x(x>=f_bounds(1) & x<=f_bounds(2));
    avg.byCell.CNQXstim1x.value(i_goodCellNum,1) = nanmean(x);
    avg.byCell.CNQXstim1x.cultureSeries(i_goodCellNum,1) = CNQXstim1x(i_cellNum,2);
    avg.byCell.CNQXstim1x.std(i_goodCellNum,1) = nanstd(x);
    avg.byCell.CNQXstim1x.n(i_goodCellNum,1) = length(x);
    i_goodCellNum = i_goodCellNum+1;
end    
