-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherrorbar_plus.m
More file actions
executable file
·93 lines (92 loc) · 2.85 KB
/
errorbar_plus.m
File metadata and controls
executable file
·93 lines (92 loc) · 2.85 KB
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
function errobar_plus(x,y,e,prop,dir)
% By Nguyen Chuong 2004/06/30
% This is to the problem of legend in errorbar
% This function put an errobar range onto plot
% Usage similar to errorbar():
% errobar_plus(x,y,e)
% errobar_plus(x,y,e,prop)
% errobar_plus(x,y,e,dir)
% errobar_plus(x,y,e,prop,dir)
% where prop is the property string like for plot()
% and dir is the vertical or horizontal direction of error
% For example,
% x = 1:10;
% y = sin(x);
% e = std(y)*ones(size(x));
% errorbar(x,y,e,'ri')
% figure
% errorbar(x,y,e,'r^')
% draws symmetric error bars of unit standard deviation.
if exist('prop')
color_list='bgrcmyk';
mark_list='.ox+*sdv^<>ph';
color='b';
for j=1:numel(prop)
for i=1:numel(color_list)
if prop(j)==color_list(i)
color=color_list(i);
break
end
end
if prop(j)==color_list(i)
break
end
end
mark='i';
for j=1:numel(prop)
for i=1:numel(mark_list)
if prop(j)==mark_list(i)
mark=mark_list(i);
break
end
end
if prop(j)==mark_list(i)
break
end
end
else
color='b'; %default values
mark='i';
end
if (exist('dir')==1) & (dir ~= 'v') & (dir ~= 'h')
dir = 'v'; %default value
elseif exist('dir')==5 % not exist
dir = 'v'; %default value
end
dx=(x(1)-x(end))/numel(x)/12; % for the case mark='i' only
dy=(y(1)-y(end))/numel(y)/12; % for the case mark='i' only
hold on
for i=1:numel(x)
if dir == 'v' % vertical errobar
plot([x(i) x(i)], [y(i)-e(i) y(i)+e(i)],color)
switch lower(mark)
case 'i'
plot([x(i)-dx x(i)+dx], [y(i)-e(i) y(i)-e(i)],color)
plot([x(i)-dx x(i)+dx], [y(i)+e(i) y(i)+e(i)],color)
case '^'
plot(x(i), y(i)-e(i),[color,'v'])
plot(x(i), y(i)+e(i),[color,'^'])
case 'v'
plot(x(i), y(i)-e(i),[color,'^'])
plot(x(i), y(i)+e(i),[color,'v'])
otherwise
plot([x(i) x(i)], [y(i)-e(i) y(i)+e(i)],[color,mark])
end
else %horizontal errorbar
plot([x(i)-e(i) x(i)+e(i)], [y(i) y(i)],color)
switch lower(mark)
case 'i'
plot([x(i)-e(i) x(i)-e(i)], [y(i)-dy y(i)+dy],color)
plot([x(i)+e(i) x(i)+e(i)], [y(i)-dy y(i)+dy],color)
case '<'
plot(x(i)-e(i), y(i),[color,'<'])
plot(x(i)+e(i), y(i),[color,'>'])
case '>'
plot(x(i)-e(i), y(i),[color,'>'])
plot(x(i)+e(i), y(i),[color,'<'])
otherwise
plot([x(i)-e(i) x(i)+e(i)], [y(i) y(i)],[color,mark])
end
end
end
hold off