Home > FMAToolbox > Plot > PlotRepeat.m

PlotRepeat

PURPOSE ^

PlotRepeat - Plot repeated (tiled) copies of the data.

SYNOPSIS ^

function h = PlotRepeat(X,Y,pattern,varargin)

DESCRIPTION ^

PlotRepeat - Plot repeated (tiled) copies of the data.

  USAGE

    h = PlotRepeat(X,Y,pattern,<options>,<options2>)

    X              abscissae
    Y              ordinates
    pattern        'xxy','xyy' or 'xxyy' depending on repeated axes
    <options>      optional list of property-value pairs (see table below)
    <options2>     additional options for 'plot' (for 'curve' mode only)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'mode'        plot type, 'curve' (default) or 'bar' (only for xxy)
     'xlim'        [min max] for X
     'ylim'        [min max] for Y
    =========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h = PlotRepeat(X,Y,pattern,varargin)
0002 
0003 %PlotRepeat - Plot repeated (tiled) copies of the data.
0004 %
0005 %  USAGE
0006 %
0007 %    h = PlotRepeat(X,Y,pattern,<options>,<options2>)
0008 %
0009 %    X              abscissae
0010 %    Y              ordinates
0011 %    pattern        'xxy','xyy' or 'xxyy' depending on repeated axes
0012 %    <options>      optional list of property-value pairs (see table below)
0013 %    <options2>     additional options for 'plot' (for 'curve' mode only)
0014 %
0015 %    =========================================================================
0016 %     Properties    Values
0017 %    -------------------------------------------------------------------------
0018 %     'mode'        plot type, 'curve' (default) or 'bar' (only for xxy)
0019 %     'xlim'        [min max] for X
0020 %     'ylim'        [min max] for Y
0021 %    =========================================================================
0022 
0023 % Copyright (C) 2012 by Michaƫl Zugaro
0024 %
0025 % This program is free software; you can redistribute it and/or modify
0026 % it under the terms of the GNU General Public License as published by
0027 % the Free Software Foundation; either version 3 of the License, or
0028 % (at your option) any later version.
0029 
0030 % Default values
0031 xLims = [];
0032 yLims = [];
0033 parameters = {};
0034 mode = 'curve';
0035 
0036 % Check number of parameters
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 % Check pattern
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 % Parse parameter list
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 % Check pattern and mode consistency
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

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005