minimum_n_minis = 30;
filenames = {'orion363','orion360'};

clear subset;
subset.amplitude = amplitude(decay<=6);
subset.area = area(decay<=6);
subset.bath = bath(decay<=6);
subset.culture = culture(decay<=6);
subset.decay = decay(decay<=6);
subset.div = div(decay<=6);
subset.fid = fid(decay<=6);
subset.rise = rise(decay<=6);
subset.time = time(decay<=6);
subset.treatment = treatment(decay<=6);

subset1.amplitude = subset.amplitude(strmatch('CNQX',subset.treatment));
subset1.area = subset.area(strmatch('CNQX',subset.treatment));
subset1.bath = subset.bath(strmatch('CNQX',subset.treatment));
subset1.culture = subset.culture(strmatch('CNQX',subset.treatment));
subset1.decay = subset.decay(strmatch('CNQX',subset.treatment));
subset1.div = subset.div(strmatch('CNQX',subset.treatment));
subset1.fid = subset.fid(strmatch('CNQX',subset.treatment));
subset1.rise = subset.rise(strmatch('CNQX',subset.treatment));
subset1.time = subset.time(strmatch('CNQX',subset.treatment));
subset1.treatment = subset.treatment(strmatch('CNQX',subset.treatment));

subset2.amplitude = subset.amplitude(strmatch('TTX',subset.treatment));
subset2.area = subset.area(strmatch('TTX',subset.treatment));
subset2.bath = subset.bath(strmatch('TTX',subset.treatment));
subset2.culture = subset.culture(strmatch('TTX',subset.treatment));
subset2.decay = subset.decay(strmatch('TTX',subset.treatment));
subset2.div = subset.div(strmatch('TTX',subset.treatment));
subset2.fid = subset.fid(strmatch('TTX',subset.treatment));
subset2.rise = subset.rise(strmatch('TTX',subset.treatment));
subset2.time = subset.time(strmatch('TTX',subset.treatment));
subset2.treatment = subset.treatment(strmatch('TTX',subset.treatment));

subset3.amplitude = subset.amplitude(strmatch('control',subset.treatment));
subset3.area = subset.area(strmatch('control',subset.treatment));
subset3.bath = subset.bath(strmatch('control',subset.treatment));
subset3.culture = subset.culture(strmatch('control',subset.treatment));
subset3.decay = subset.decay(strmatch('control',subset.treatment));
subset3.div = subset.div(strmatch('control',subset.treatment));
subset3.fid = subset.fid(strmatch('control',subset.treatment));
subset3.rise = subset.rise(strmatch('control',subset.treatment));
subset3.time = subset.time(strmatch('control',subset.treatment));
subset3.treatment = subset.treatment(strmatch('control',subset.treatment));

[x1 x2] = getMiniAmpByCell(filenames{1},subset1.culture,subset1.fid,subset1.amplitude);
%[y1 y2] = getMiniAmpByCell(filenames,subset2.culture,subset2.fid,subset2.amplitude);
[z1 z2] = getMiniAmpByCell(filenames{2},subset3.culture,subset3.fid,subset3.amplitude);

[x3 x4] = getMiniAmpSample(x1,x2,minimum_n_minis);
%[y3 y4] = getMiniAmpSample(y1,y2,minimum_n_minis);
[z3 z4] = getMiniAmpSample(z1,z2,minimum_n_minis);

hold off;


x_cumhist = [];
for i = 1:length(x4)
    x_cumhist = [x_cumhist; cell2mat(x3(i,1))];
end
plotAmpCumHist(x_cumhist,'r'); %CNQX
hold on;

% y_cumhist = [];
% for i = 1:length(y4)
%     y_cumhist = [y_cumhist; cell2mat(y3(i,1))];
% end
% plotAmpCumHist(y_cumhist,'b'); %TTX

z_cumhist = [];
for i = 1:length(z4)
    z_cumhist = [z_cumhist; cell2mat(z3(i,1))];
end
plotAmpCumHist(z_cumhist,'k'); %CONTROL
%legend('CNQX-treated','control','Location','SouthEast')
title([filenames{1} ' (CNQX-treated) and ' filenames{2} ' (control)']);
xlimits = xlim; ylimits = ylim;
text(xlimits(2)*0.99,ylimits(2)*0.01,['n_{' filenames{1} '} = ' num2str(length(x4)),...
    10,'n_{' filenames{2} '} = ' num2str(length(z4))],'HorizontalAlignment','right','VerticalAlignment','bottom');
