File Exchange

## barerrorbar(varargi​n)

version 2.0.0.0 (6.29 KB) by Kenneth Morton

### Kenneth Morton (view profile)

Create a bar plot with error bars.

Updated 01 Apr 2016

Barerrorbar() creates a bar plot with error bars. Although, not the first function to accomplish this task, barerrorbar() differs in that it directly calls the MATLAB functions bar() and errorbar() so that the options of both functions are preserved. For example:
x = 0.2*randn(3,4,100) + 1;
xMeans = mean(x,3);
xMeansL = repmat(3*0.2/10,3,4);
xMeansU = repmat(4*0.2/10,3,4);
barerrorbar({3:5,xMeans,'m'}, {repmat((3:5)',1,4),...
xMeans, xMeansL,xMeansU,'bx'});

### Cite As

Kenneth Morton (2020). barerrorbar(varargin) (https://www.mathworks.com/matlabcentral/fileexchange/9541-barerrorbar-varargin), MATLAB Central File Exchange. Retrieved .

Andrea Gerbotto

Great! Thanks!

Achut

Xiaohui Liu

### Xiaohui Liu (view profile)

works like a charm for M > 1, but breaks down when M = 1. See below:

hold off;
M = 3;
N = 6;
x = rand(M, N);
lo = rand(M, N) * 0.5;
hi = rand(M, N) * 0.5;
% bar(1:M, x);
% hold on;
% errorbar(repmat((1:M)', 1, N), x, lo, hi, 'rx');
barerrorbar({1:M, x}, {repmat((1:M)', 1, N), x, lo, hi, 'rx'});

André

### André (view profile)

Since it is based on bar and error it is intuitive and easy to use. Got the plot I wanted in less than three seconds.

B I

### B I (view profile)

Try setting the groups by using handle as described in the bar function
h=barerrorbar
>> set(h(1),'facecolor','white')
>> set(h(2),'facecolor','black')

Omar Mian

### Omar Mian (view profile)

For the final figure in the example code, I want to set the first group of bars (at x = 1) black and the second group (at x = 2) red.

Adapting the example code, I assumed I could do this:
figure
barerrorbar({1,xMeans(1,:),'k'}, {[1 1 1 1],xMeans(1,:), xMeansL(1,:),xMeansU(1,:),'bx'});
hold on
barerrorbar({2,xMeans(2,:),'r'}, {[2 2 2 2],xMeans(2,:), xMeansL(2,:),xMeansU(2,:),'bx'});

However, this gives an error. Could someone please advise on what the code should be?
Thanks.

Daniel

### Daniel (view profile)

Very useful, is there anyway to make the error bars one sided? By that I mean to only have the top half of the error bar showing as opposed to the entire thing?

Luka

ollydbg

### ollydbg (view profile)

Great! It is better than the other bar and error bar related code

Darik

### Darik (view profile)

Perfect. Every other bar/errorbar function on the FEX should be deleted.

Carolina Wählby

Beautiful!
I tried hard to find this functionality in Matlab, but almost decided to do my plotting in Excel to get arrorbars on my barplots... Thanks!

Leah Acker

Great program.

 1 Apr 2016 2.0.0.0 Fix a minor bug concerning row vector inputs. 21 Mar 2006 1.0.0.0 Updated the file to remove M-Lint messages. 10 Jan 2006 Fixed a spelling error in the description. Resized the example picture.
##### MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
##### Platform Compatibility
Windows macOS Linux