load('C:\Users\mingfaifong\Documents\2012-10-30_juju1-jujuI5372-jujuI5388_patch-analysis\amplitude_30events_NoNorm_01\ctrl-TTX-TTXCTZ_normToTTX.mat')

[h1 p1] = ttest2(ctrl_avg_noNorm,TTX_avg_noNorm)
[h2 p2] = ttest2(TTX_avg_noNorm,TTXCTZ_avg_noNorm)
[h3 p3] = ttest2(ctrl_avg_noNorm,TTXCTZ_avg_noNorm)

%%
plotcolors = {[0 0 0],[0 0.2 0.7],[0.9 0 0],[0.1 0.7 0.1],[1 0.5 0],[0.6 0 0.7]}; %black, blue, red, green, orange, purple

figure(1); subplot(1,2,1);
bar(1,mean(ctrl_avg_noNorm),'FaceColor',plotcolors{1},'LineWidth',1); hold on;
errorbar(1,mean(ctrl_avg_noNorm),std(ctrl_avg_noNorm)/sqrt(length(ctrl_avg_noNorm)),'-k','LineWidth',2);

bar(2,mean(TTX_avg_noNorm),'FaceColor',plotcolors{1},'LineWidth',1)
errorbar(2,mean(TTX_avg_noNorm),std(TTX_avg_noNorm)/sqrt(length(TTX_avg_noNorm)),'-k','LineWidth',2);

bar(3,mean(TTXCTZ_avg_noNorm),'FaceColor',plotcolors{1},'LineWidth',1)
errorbar(3,mean(TTXCTZ_avg_noNorm),std(TTXCTZ_avg_noNorm)/sqrt(length(TTXCTZ_avg_noNorm)),'-k','LineWidth',2);

set(gca,'XTick',[1,2,3],'XTickLabel',{'control','CNQX','CNQX+stim'},'FontSize',14);
ylabel('mEPSC Amplitude (pA)','FontSize',16)
box off;
axis([0.25 3.75 0 1.3])
axis square;

formatSpec =  '%6.4f';

plot([1 1.9],[1.1 1.1],'-k','LineWidth',2); text(1.5,1.1,['p=' num2str(p1,formatSpec)],'HorizontalAlignment','center','FontSize',10,'VerticalAlignment','bottom');
plot([2.1 3],[1.1 1.1],'-k','LineWidth',2); text(2.5,1.1,['p=' num2str(p2,formatSpec)],'HorizontalAlignment','center','FontSize',10,'VerticalAlignment','bottom');
plot([1 3],[1.2 1.2],'-k','LineWidth',2); text(2,1.2,['p=' num2str(p3,formatSpec)],'HorizontalAlignment','center','FontSize',10,'VerticalAlignment','bottom');

text(1,0.6,['n=',num2str(length(ctrl_avg_noNorm))],'Color',[1 1 1],'HorizontalAlignment','center','FontSize',14);
text(2,0.6,['n=',num2str(length(TTX_avg_noNorm))],'Color',[1 1 1],'HorizontalAlignment','center','FontSize',14);
text(3,0.6,['n=',num2str(length(TTXCTZ_avg_noNorm))],'Color',[1 1 1],'HorizontalAlignment','center','FontSize',14);

hold off;

%%

alldata = [ctrl_samp_noNorm; TTX_samp_noNorm;TTXCTZ_samp_noNorm];
dt = 0.1;
bin = min(alldata)-dt:dt:max(alldata);

ctrl_nhist = histc(ctrl_samp_noNorm,bin);
TTX_nhist = histc(TTX_samp_noNorm,bin);
TTXCTZ_nhist = histc(TTXCTZ_samp_noNorm,bin);

ctrl_cumhist = cumsum(ctrl_nhist);
TTX_cumhist = cumsum(TTX_nhist);
TTXCTZ_cumhist = cumsum(TTXCTZ_nhist);

subplot(1,2,2);
plot(bin,ctrl_cumhist/max(ctrl_cumhist),'Color',plotcolors{1},'LineWidth',3); hold on;
plot(bin,TTX_cumhist/max(TTX_cumhist),'Color',plotcolors{2},'LineWidth',3);
plot(bin,TTXCTZ_cumhist/max(TTXCTZ_cumhist),'Color',plotcolors{3},'LineWidth',3);
hold off;
axis([0 3.5 0 1.02]);

legend('control','TTX','TTX+CTZ','Location','SouthEast');
set(gca,'FontSize',14,'XTick',0:0.5:3.5);
xlabel('mEPSC Amplitude (pA)','FontSize',14)
ylabel('Fraction of Events','FontSize',16)
box off;
axis square;