3.0

3.0 | 5 ratings Rate this file 160 downloads (last 30 days) File Size: 1.91 KB File ID: #9377

Barerror

by Francisco de Castro

 

16 Dec 2005 (Updated 28 Feb 2008)

Code covered by BSD License  

Plots a multiple bar graph with error bars

Download Now | Watch this File

File Information
Description

BarrError combines the functions 'bar' and 'errorbar' in a single function. As far as I know, 'errorbar' cannot accomodate several bars per X point (as 'bar' does), so is not easy to plot one of the most common graph types (at least in natural sciences). 'BarError' tries to fill this gap.

Sintax:
barerror(X,Y,E,width,ycolor,ecolor,varargin)
x: vector of X values
y: vector or matrix of Y values
e: vector or matrix of error values (plotted simmetrically)
width: bar width
ycolor: one-letter color code for the bar
ecolor: one-letter color code for the error bar

Warnings
Vector x, and vector/array y and e must be the same length
y and e must have the same number of columns if they are arrays
Length of ycolor and ecolor must be equal to the number of columns of y and e

Example:
x= (1:5)';
y= 20*rand(length(x),3);
e= rand(length(x),3);
ycolor= ['b','r','g'];
ecolor= ['k','k','k'];
labels= {'G1','G2','G3','G4','G5'};
barerror(x,y,e,1,ycolor,ecolor,labels);

Acknowledgements
This submission has inspired the following:
barerrorbar
MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
30 Jan 2006 Swapnil G

Did not work...gave an error that matrix dimensions must agree

21 Feb 2006 Nina Gateman

It didn't work for me either. For what I want to do; I don't need to input the x axis values (since I'm plotting "group names" eg group 1 result, group2 result etc). So the Xaxis for me is the actual group name (a String) and its only the result values I need to plot against the y xais, therefore the syntax should allow for only needing to input yaxis matrix....

16 Apr 2006 Michael Frank

worked fine for me; it's still not the ideal matlab bar graph function, which would allow good axis labeling, error bars, color choice, etc.

24 Jan 2007 Doris Tsao

didn't work for me... gave error that input dimensions must agree

05 Nov 2007 Brahim HAMADICHAREF

Indeed it takes time to test one simple
example but here is one !

nN = 5;
nM = 4;
X = [1:nN]';
Y = 0.5+0.5*rand(nN, nM);
E = 0.1*rand(nN, nM);
barerror(X, Y, E, 1, 'k')

Note that I added the mode 'group'
for bar function call

Brahim

28 Feb 2008 Francisco de Castro

I must say: the "errors" reported by Swapnil and Tsao are not errors in the function but in their input data, as the function kindly reminds them.
The comment by Gateman is now included.

08 Jan 2009 Falofolio  
08 Jan 2009 Falofolio

Works perfect. Thanks for this great script.

Please login to add a comment or rating.
Updates
07 Nov 2007

Included:
Help
Example
Colors for the bars
Colors for the error bars
Labels for x axis

28 Feb 2008

Update description

Tag Activity for this File
Tag Applied By Date/Time
specialized Francisco de Castro 22 Oct 2008 08:10:00
plotting Francisco de Castro 22 Oct 2008 08:10:00
graph bar error deviation Francisco de Castro 22 Oct 2008 08:10:00
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com