This repository has been archived by the owner on Feb 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
herrorbar.m
167 lines (149 loc) · 4.1 KB
/
herrorbar.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
function hh = herrorbar(x, y, l, u, symbol)
%HERRORBAR Horizontal Error bar plot.
% HERRORBAR(X,Y,L,R) plots the graph of vector X vs. vector Y with
% horizontal error bars specified by the vectors L and R. L and R contain the
% left and right error ranges for each point in X. Each error bar
% is L(i) + R(i) long and is drawn a distance of L(i) to the right and R(i)
% to the right the points in (X,Y). The vectors X,Y,L and R must all be
% the same length. If X,Y,L and R are matrices then each column
% produces a separate line.
%
% HERRORBAR(X,Y,E) or HERRORBAR(Y,E) plots X with error bars [X-E X+E].
% HERRORBAR(...,'LineSpec') uses the color and linestyle specified by
% the string 'LineSpec'. See PLOT for possibilities.
%
% H = HERRORBAR(...) returns a vector of line handles.
%
% Example:
% x = 1:10;
% y = sin(x);
% e = std(y)*ones(size(x));
% herrorbar(x,y,e)
% draws symmetric horizontal error bars of unit standard deviation.
%
% This code is based on ERRORBAR provided in MATLAB.
%
% See also ERRORBAR
% Jos van der Geest
% email: [email protected]
%
% License: BSD
%
% File history:
% August 2006 (Jos): I have taken back ownership. I like to thank Greg Aloe from
% The MathWorks who originally introduced this piece of code to the
% Matlab File Exchange.
% September 2003 (Greg Aloe): This code was originally provided by Jos
% from the newsgroup comp.soft-sys.matlab:
% http://newsreader.mathworks.com/[email protected]^[email protected]
% After unsuccessfully attempting to contact the orignal author, I
% decided to take ownership so that others could benefit from finding it
% on the MATLAB Central File Exchange.
%
% JSB added logscale functionality on 9/26/14
if min(size(x))==1,
npt = length(x);
x = x(:);
y = y(:);
if nargin > 2,
if ~ischar(l),
l = l(:);
end
if nargin > 3
if ~ischar(u)
u = u(:);
end
end
end
else
[npt] = size(x);
end
if nargin == 3
if ~ischar(l)
u = l;
symbol = '-';
else
symbol = l;
l = y;
u = y;
y = x;
[m,n] = size(y);
x(:) = (1:npt)'*ones(1,n);
end
end
if nargin == 4
if ischar(u),
symbol = u;
u = l;
else
symbol = '-';
end
end
if nargin == 2
l = y;
u = y;
y = x;
[m,n] = size(y);
x(:) = (1:npt)'*ones(1,n);
symbol = '-';
end
u = abs(u);
l = abs(l);
if ischar(x) || ischar(y) || ischar(u) || ischar(l)
error('Arguments must be numeric.')
end
if ~isequal(size(x),size(y)) || ~isequal(size(x),size(l)) || ~isequal(size(x),size(u)),
error('The sizes of X, Y, L and U must be the same.');
end
logscale = strcmp(get(gca,'YScale'),'log');
if(logscale)
tee = 10.^(log10((max(y(:))/min(y(:))))/100);
else
tee = (max(y(:))-min(y(:)))/100; % make tee .02 y-distance for error bars
end
% changed from errorbar.m
xl = x - l;
xr = x + u;
if(logscale)
ytop = y * tee;
ybot = y / tee;
else
ytop = y + tee;
ybot = y - tee;
end
n = size(y,2);
% end change
% Plot graph and bars
hold_state = ishold;
%cax = newplot;
%next = lower(get(cax,'NextPlot'));
% build up nan-separated vector for bars
% changed from errorbar.m
xb = zeros(npt*9,n);
xb(1:9:end,:) = xl;
xb(2:9:end,:) = xl;
xb(3:9:end,:) = NaN;
xb(4:9:end,:) = xl;
xb(5:9:end,:) = xr;
xb(6:9:end,:) = NaN;
xb(7:9:end,:) = xr;
xb(8:9:end,:) = xr;
xb(9:9:end,:) = NaN;
yb = zeros(npt*9,n);
yb(1:9:end,:) = ytop;
yb(2:9:end,:) = ybot;
yb(3:9:end,:) = NaN;
yb(4:9:end,:) = y;
yb(5:9:end,:) = y;
yb(6:9:end,:) = NaN;
yb(7:9:end,:) = ytop;
yb(8:9:end,:) = ybot;
yb(9:9:end,:) = NaN;
% end change
[ls,col,mark,msg] = colstyle(symbol); if ~isempty(msg), error(msg); end
symbol = [ls mark col]; % Use marker only on data part
esymbol = ['-' col]; % Make sure bars are solid
h = plot(xb,yb,esymbol); hold on
h = [h;plot(x,y,symbol)];
if ~hold_state, hold off; end
if nargout>0, hh = h; end