function [output_h,output_p,output_ci,output_stats] = mean_errorbar(pre, post) % [output_h,output_p,output_ci,output_stats] = mean_errorbar(pre, post) % mean_errorbar plot bar graph with mean value and dot graph with % individual values for both pre and post data % % Inputs (required): % - pre and post: two distributions. Need not be the same size. % Outputs: % - figure ploting with mean and errorbar % - pval: ttest results % Xian Zhang email: xzhang@cshl.edu % plot mean and errorbar bar(1,mean2(pre),.2,'facecolor',[.5 .5 .5]) hold on, errorbar(1,mean2(pre),std2(pre)/sqrt(length(pre)),'Linewidth',2,'color',[.5 .5 .5]) hold on,bar(2,mean2(post),.2,'facecolor',[.5 .5 .5]) hold on, errorbar(2,mean2(post),std2(post)/sqrt(length(post)),'Linewidth',2,'color',[.5 .5 .5]) % dot ploting with individual data x = ones(size(pre)); xx = x*2; hold on plot(x,pre,'o','color',[0 0 0]) hold on, plot(xx,post,'o','color',[0 0 0]) for i = 1:length(pre) line([x(i) xx(i)],[pre(i) post(i)],'color',[.5 .5 .5]) end ax = gca; ax.XTick = [1 2]; ax.XTickLabel = {'pre','post'}; % xlabel('Time (s)') box off [h,p,ci,stats] = ttest(pre,post) output_h = h; output_p = p; output_ci = ci; output_stats = stats; end