-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhline.m
More file actions
111 lines (103 loc) · 3.35 KB
/
Copy pathhline.m
File metadata and controls
111 lines (103 loc) · 3.35 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function hhh=hline(y,in1,in2,varargin)
%% Copyright notice
% By Brandon Kuczenski for Kensington Labs (brandon_kuczenski@kensingtonlabs.com) 8 November 2001
% Copyright (c) 2001, Brandon Kuczenski
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%%
if length(y)>1 % vector input
for I=1:length(y)
if nargin == 1
linetype='r:';
label='';
elseif nargin == 2
if ~iscell(in1)
in1={in1};
end
if I>length(in1)
linetype=in1{end};
else
linetype=in1{I};
end
label='';
elseif nargin > 2
if ~iscell(in1)
in1={in1};
end
if ~iscell(in2)
in2={in2};
end
if I>length(in1)
linetype=in1{end};
else
linetype=in1{I};
end
if I>length(in2)
label=in2{end};
else
label=in2{I};
end
end
h(I)=hline(y(I),linetype,label);
end
else
if nargin ==1
linetype = 'r:';
label = '';
elseif nargin == 2
linetype = in1;
label = '';
elseif nargin > 2
linetype = in1;
label = in2;
end
g=ishold(gca);
hold on
x=get(gca,'xlim');
h=plot(x,[y y],linetype);
if ~isempty(label)
yy=get(gca,'ylim');
yrange=yy(2)-yy(1);
yunit=(y-yy(1))/yrange;
if yunit<0.2
text(x(1)+0.02*(x(2)-x(1)),y+0.02*yrange,label,'color',get(h,'color'))
else
text(x(1)+0.02*(x(2)-x(1)),y-0.02*yrange,label,'color',get(h,'color'))
end
end
if g==0
hold off
end
if nargin==4
handlevisibility = varargin{1};
else
handlevisibility ='off';
end
set(h,'tag','vline','handlevisibility',handlevisibility);
% this last part is so that it doesn't show up on legends
% NOT ALWAYS A GOOD IDEA AS THEN THE LINE DOES NOT DISAPPEAR WHEN CALLING CLA
end % else
if nargout
hhh=h;
end