/ concept-collection / windowedFourierProjection
Sign in
concept-collection / windowedFourierProjection
107 lines · 3.0 KBCodeBlameHistory
8748c66added codenalhassanieh 1function hhh=hline(y,in1,in2)
2% function h=hline(y, linetype, label)
3%
4% Draws a horizontal line on the current axes at the location specified by 'y'. Optional arguments are
5% 'linetype' (default is 'r:') and 'label', which applies a text label to the graph near the line. The
6% label appears in the same color as the line.
7%
8% The line is held on the current axes, and after plotting the line, the function returns the axes to
9% its prior hold state.
11% The HandleVisibility property of the line object is set to "off", so not only does it not appear on
12% legends, but it is not findable by using findobj. Specifying an output argument causes the function to
13% return a handle to the line, so it can be manipulated or deleted. Also, the HandleVisibility can be
14% overridden by setting the root's ShowHiddenHandles property to on.
15%
16% h = hline(42,'g','The Answer')
17%
18% returns a handle to a green horizontal line on the current axes at y=42, and creates a text object on
19% the current axes, close to the line, which reads "The Answer".
20%
21% hline also supports vector inputs to draw multiple lines at once. For example,
22%
23% hline([4 8 12],{'g','r','b'},{'l1','lab2','LABELC'})
24%
25% draws three lines with the appropriate labels and colors.
26%
27% By Brandon Kuczenski for Kensington Labs.
28% brandon_kuczenski@kensingtonlabs.com
29% 8 November 2001
31if length(y)>1 % vector input
32 for I=1:length(y)
33 switch nargin
34 case 1
35 linetype='r:';
36 label='';
37 case 2
38 if ~iscell(in1)
39 in1={in1};
40 end
41 if I>length(in1)
42 linetype=in1{end};
43 else
44 linetype=in1{I};
45 end
46 label='';
47 case 3
48 if ~iscell(in1)
49 in1={in1};
50 end
51 if ~iscell(in2)
52 in2={in2};
53 end
54 if I>length(in1)
55 linetype=in1{end};
56 else
57 linetype=in1{I};
58 end
59 if I>length(in2)
60 label=in2{end};
61 else
62 label=in2{I};
63 end
64 end
65 h(I)=hline(y(I),linetype,label);
66 end
67else
68 switch nargin
69 case 1
70 linetype='r:';
71 label='';
72 case 2
73 linetype=in1;
74 label='';
75 case 3
76 linetype=in1;
77 label=in2;
78 end
83 g=ishold(gca);
84 hold on
86 x=get(gca,'xlim');
87 h=plot(x,[y y],linetype);
88 if ~isempty(label)
89 yy=get(gca,'ylim');
90 yrange=yy(2)-yy(1);
91 yunit=(y-yy(1))/yrange;
92 if yunit<0.2
93 text(x(1)+0.02*(x(2)-x(1)),y+0.02*yrange,label,'color',get(h,'color'))
94 else
95 text(x(1)+0.02*(x(2)-x(1)),y-0.02*yrange,label,'color',get(h,'color'))
96 end
97 end
99 if g==0
100 hold off
101 end
102 set(h,'tag','hline','handlevisibility','off') % this last part is so that it doesn't show up on legends
103end % else
105if nargout
106 hhh=h;
107end
moveopenescclose