0001 function h = PlotRepeat(X,Y,pattern,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 xLims = [];
0032 yLims = [];
0033 parameters = {};
0034 mode = 'curve';
0035
0036
0037 if nargin < 3,
0038 error('Incorrect number of parameters (type ''help <a href="matlab:help PlotRepeat">PlotRepeat</a>'' for details).');
0039 end
0040
0041
0042 if ~isastring(pattern,'xxy','xyy','xxyy'),
0043 error('Incorrect pattern (type ''help <a href="matlab:help PlotRepeat">PlotRepeat</a>'' for details).');
0044 end
0045
0046
0047 for i = 1:2:length(varargin),
0048 if ~ischar(varargin{i}),
0049 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help PlotRepeat">PlotRepeat</a>'' for details).']);
0050 end
0051 switch(lower(varargin{i})),
0052 case 'mode',
0053 mode = varargin{i+1};
0054 if ~isastring(mode,'curve','bar'),
0055 error('Incorrect value for property ''mode'' (type ''help <a href="matlab:help PlotRepeat">PlotRepeat</a>'' for details).');
0056 end
0057 case 'xlim',
0058 xLims = varargin{i+1};
0059 if ~isdvector(xLims,'<','#2'),
0060 error('Incorrect value for property ''xlim'' (type ''help <a href="matlab:help PlotRepeat">PlotRepeat</a>'' for details).');
0061 end
0062 case 'ylim',
0063 yLims = varargin{i+1};
0064 if ~isdvector(yLims,'<','#2'),
0065 error('Incorrect value for property ''ylim'' (type ''help <a href="matlab:help PlotRepeat">PlotRepeat</a>'' for details).');
0066 end
0067 otherwise,
0068 parameters = varargin{i:end};
0069 if ~isa(parameters,'cell'), parameters = {parameters}; end
0070 break;
0071 end
0072 end
0073
0074
0075 if strcmp(mode,'bar') && ~strcmp(pattern,'xxy'),
0076 error('Bar plots can only be used for xxy pattern (type ''help <a href="matlab:help PlotRepeat">PlotRepeat</a>'' for details).');
0077 end
0078
0079 X = X(:);
0080 Y = Y(:);
0081
0082 if isempty(X) || isempty(Y),
0083 return;
0084 end
0085
0086 if isempty(xLims),
0087 xLims = [min(X) max(X)];
0088 end
0089 if isempty(yLims),
0090 yLims = [min(Y) max(Y)];
0091 end
0092
0093 hold on;
0094 switch pattern,
0095 case 'xxy',
0096 if strcmp(mode,'curve'),
0097 h = plot([X;X+diff(xLims)],[Y;Y],parameters{:});
0098 else
0099 [X,i] = unique([X;X+diff(xLims)]);
0100 Y = [Y;Y];
0101 Y = Y(i);
0102 h = bar(X,Y,'hist');
0103 end
0104 xlim(ConsolidateIntervals([xlim;xLims;xLims+diff(xLims)]));
0105 ylim(ConsolidateIntervals([ylim;yLims]));
0106 case 'xyy',
0107 h = plot([X;X],[Y;Y+diff(yLims)],parameters{:});
0108 xlim(ConsolidateIntervals([xlim;xLims]));
0109 ylim(ConsolidateIntervals([ylim;yLims;yLims+diff(yLims)]));
0110 case 'xxyy',
0111 h = plot([X;X+diff(xLims);X;X+diff(xLims)],[Y;Y;Y+diff(yLims);Y+diff(yLims)],parameters{:});
0112 xlim(ConsolidateIntervals([xlim;xLims;xLims+diff(xLims)]));
0113 ylim(ConsolidateIntervals([ylim;yLims;yLims+diff(yLims)]));
0114 end