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
|
%------------------------------------------------------------------------------
% PROGRAM NAME: Plot horizontal lines
% FILE: plotvertline.m
% AUTHOR: Andri M. Gretarsson
% DATE: 02/03/03
%
% SYNTAX: linehandles=plothorline(y,xmin,xmax <,marker,plotstyle>)
%
% Plots horizontal lines at the positions listed in the vector y. The vertical
% lines extend from xmin to xmax and are ploted with the markerstyle and
% color defined by marker if specified (same syntax as the marker in matlab's
% built in function plot. Exits with hold set to off. If plotstyle is specified
% then the plotstyle will be linear-linear, lin-log, log-lin or log-log,
% depending on whether plotstyle is 'plot', 'semilogx', 'semilogy', or 'loglog'.
%
% If 'marker' is a string whose first character is an apostrophe ('),
% the marker string in interpreted literally as part of the command, as in:
% eval(['plot([xmin xmax],[y(i) y(i)],',marker,')']);
%
% If the first character of marker is not an apostrophe, the marker string is
% just inserted into the command as usual without using eval, namely:
% plot([xmin xmax],[y(i) y(i)],marker).
%
% Thus, for example:
% marker = '''b-'',''LineWidth'',2' results in the plot command
% plot(x,y,'b-','LineWidth',2) being evaluated.
%
% marker = 'b-' has the same effect as marker = '''b-''', namely
% plot(x,y,'b-'), in the first case directly via plot(x,y,'b-') and
% in the second case via eval(['plot(x,y,',marker,')']).
%
% If xmin=0 and xmax=0, then ymin and ymax are obtained from the current
% axes.
%
% LAST UPDATED: 03/13/03
%
%-------------------------------------------------------------------------------
% SYNTAX: linehandles=plothorline(y,xmin,xmax <,marker,plotstyle>)
%-------------------------------------------------------------------------------
function linehandles=plothorline(y,xmin,xmax,varargin);
if nargin>=4, marker=varargin{1}; else marker='b-'; end
if nargin>=5,
plotstyle=varargin{2};
else plotstyle='plot';
end
if xmin==0 & xmax==0
range=get(gca,'XLim');
xmin=range(1);
xmax=range(2);
end
NextPlot_current=get(gca,'NextPlot'); % Get the original 'hold' state
h=zeros(length(y),1);
if plotstyle(1)=='p'
for i=1:length(y)
if marker(1)==''''
eval(['h(i)=plot([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
else
h(i)=plot([xmin xmax],[y(i) y(i)],marker); hold on;
end
end
else
if plotstyle(1)=='l'
for i=1:length(y)
if marker(1)==''''
eval(['h(i)=loglog([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
else
h(i)=loglog([xmin xmax],[y(i) y(i)],marker); hold on;
end
end
else
if (length(plotstyle)==8 &plotstyle(8)=='x')
for i=1:length(y)
if marker(1)==''''
eval(['h(i)=semilogx([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
else
h(i)=semilogx([xmin xmax],[y(i) y(i)],marker); hold on;
end
end
else
if (length(plotstyle)==8 &plotstyle(8)=='y')
for i=1:length(y)
if marker(1)==''''
eval(['h(i)=semilogy([xmin xmax],[y(i) y(i)],',marker,')']); hold on;
else
h(i)=semilogy([xmin xmax],[y(i) y(i)],marker); hold on;
end
end
end;end;end;end;
if NextPlot_current(1)=='r' % reset to the original 'hold' state
set(gca,'NextPlot','replace')
else
set(gca,'NextPlot','add');
end
linehandles=h;
|