0001 function PlotIntervals(intervals,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 color = [0.9 0.9 0.9];
0036 alphaValue = 1;
0037 style = 'rectangles';
0038 direction = 'v';
0039
0040 if nargin < 1,
0041 error('Incorrect number of parameters (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
0042 end
0043 if size(intervals,2) ~= 2,
0044 error('Incorrect list of intervals (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
0045 end
0046
0047
0048 parsed = false;
0049 if (nargin == 2 || nargin == 3) && isastring(lower(varargin{1}),'rectangles','bars'),
0050 style = lower(varargin{1});
0051 parsed = true;
0052 end
0053 if nargin == 3 && isastring(lower(varargin{2}),'h','v'),
0054 direction = lower(varargin{2});
0055 parsed = true;
0056 end
0057
0058
0059 if ~parsed,
0060 for i = 1:2:length(varargin),
0061 if ~ischar(varargin{i}),
0062 error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).']);
0063 end
0064 switch(lower(varargin{i})),
0065 case 'style',
0066 style = lower(varargin{i+1});
0067 if ~isastring(style,'bars','rectangles'),
0068 error('Incorrect value for property ''style'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
0069 end
0070 case 'direction',
0071 direction = lower(varargin{i+1});
0072 if ~isastring(direction,'h','v'),
0073 error('Incorrect value for property ''direction'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
0074 end
0075 case 'color',
0076 color = lower(varargin{i+1});
0077 if ~isastring(color,'r','g','b','c','m','y','k','w') && ~isdvector(color,'#3','>=0','<=1'),
0078 error('Incorrect value for property ''direction'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
0079 end
0080 case 'alpha',
0081 alphaValue = varargin{i+1};
0082 if ~isdscalar(alphaValue,'>=0','<=1'),
0083 error('Incorrect value for property ''alpha'' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).');
0084 end
0085 otherwise,
0086 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help PlotIntervals">PlotIntervals</a>'' for details).']);
0087 end
0088 end
0089 end
0090
0091 hold on;
0092 yLim = ylim;
0093 xLim = xlim;
0094 if strcmp(style,'bars'),
0095 for i = 1:size(intervals,1),
0096 if strcmp(direction,'v'),
0097 plot([intervals(i,1) intervals(i,1)],yLim,'Color',[0 0.75 0]);
0098 plot([intervals(i,2) intervals(i,2)],yLim,'Color',[0.9 0 0]);
0099 else
0100 plot(xLim,[intervals(i,1) intervals(i,1)],'Color',[0 0.75 0]);
0101 plot(xLim,[intervals(i,2) intervals(i,2)],'Color',[0.9 0 0]);
0102 end
0103 end
0104 else
0105 for i=1:size(intervals,1),
0106 if strcmp(direction,'v'),
0107 dx = intervals(i,2)-intervals(i,1);
0108 dy = yLim(2)-yLim(1);
0109 rec = patch(intervals(i,1)+[0 0 dx dx],yLim(1)+[0 dy dy 0],color,'LineStyle','none');
0110 alpha(rec,alphaValue);
0111 else
0112 dx = xLim(2)-xLim(1);
0113 dy = intervals(i,2)-intervals(i,1);
0114 rec = patch(xLim(1)+[0 0 dx dx],intervals(i,1)+[0 dy dy 0],color,'LineStyle','none');
0115 alpha(rec,alphaValue);
0116 alpha(rec,alphaValue);
0117 end
0118 uistack(rec,'bottom');
0119 end
0120 end
0121
0122