Home > classes > @ao > iplot.m

iplot

PURPOSE ^

IPLOT provides an intelligent plotting tool for LTPDA.

SYNOPSIS ^

function varargout = iplot(varargin)

DESCRIPTION ^

 IPLOT provides an intelligent plotting tool for LTPDA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: IPLOT provides an intelligent plotting tool for LTPDA.

 CALL:               hfig = iplot (a,pl)
              [hfig, hax] = iplot (a,pl)
         [hfig, hax, hli] = iplot (a,pl)

 INPUTS:      pl   - a parameter list
              a    - input analysis object

 OUTPUTS:     hfig - handles to figures
              hax  - handles to axes
              hli  - handles to lines

 Plot parameters:

             'Arrangement' - select the plot layout:
                           'single'   - plots all AOs on individual figures
                           'stacked'  - plots all AOs on the same axes [default]
                           'subplots' - plots all AOs on subplots

             'Function'    - specify the plot function:
                             'plot', 'stairs', 'stem'
                             [default: 'plot']
                             *** doesn't work for xyzdata AOs

 Line parameters:

        The following properties take cell array values. If the length of
        the cell array is shorter than the number of lines to plot, the
        remaining lines will be plotted with the default options. If the
        cell array is of length 2 and the first cell contains the string
        'all', then the second cell is used to set the propery of all
        lines.

             'LineColors' - a cell array of color definitions for each line.

             'LineStyles' - a cell array of line styles.

             'Markers'    - a cell array of markers.

             'LineWidths' - a cell array of line widths. If the length of the
                            cell array is shorter than the number of lines to
                            plot, the remaining lines will be plotted with
                            the default line width.

 Axes parameters:

             'Legends' - specify a cell array of strings to be used for
                         the plot legends. If a cell contains an empty
                         string, the default legend string is built.
                         If a single string 'off' is given instead of a
                         cell array, then the legends are all switched
                         off.

             'XLabels' - Specify the labels to be used on the x-axis. The
                         units are added from the data object 'xunits'
                         property.

             'YLabels' - Specify the labels to be used on the y-axis. The
                         units are added from the data object 'yunits'
                         property. If the object contains complex data,
                         you should specify two y-labels for that object.

    The following axis properties also work with the 'all' keyword as
    described above in the line properties section.

             'XScales' - Specify the scales to be used on the x-axes.

             'YScales' - Specify the scales to the used on the y-axes. If
                         an object contains complex data, you should
                         specify two y-labels for that object.

             'XRanges' - Specify the ranges to be displayed on the x-axes.

             'YRanges' - Specify the ranges to the displayed on the
                         y-axes.

 EXAMPLES:

 1) Plot two time-series AOs with different colors, line styles, and widths

   pl = plist('Linecolors', {'g', 'k'}, 'LineStyles', {'', '--'}, 'LineWidths', {1, 4});
   iplot(tsao1, tsao2, pl);

 2) Plot two time-series AOs in subplots. Also override the second legend
    text and the first line style.

   pl = plist('Arrangement', 'subplots', 'LineStyles', {'--'}, 'Legends', {'', 'My Sine Wave'});
   iplot(tsao1, tsao2, pl);

 3) Plot two time-series AOs taking the square of the y-values of the
    first AO and the log of the x-values of the second AO.

   pl = plist('Arrangement', 'subplots', 'YMaths', 'y.^2', 'XMaths', {'', 'log(x)'});
   iplot(tsao1, tsao2, pl);

 4) Plot two frequency-series AOs on subplots with the same Y-scales and
    Y-ranges

   pl1 = plist('Yscales', {'All', 'lin'});
   pl2 = plist('arrangement', 'subplots', 'YRanges', {'All', [1e-6 100]});
   iplot(fsd1, fsd2, pl1, pl2)


 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('iplot')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('iplot', 'None')

 VERSION:     $Id: iplot.m,v 1.48 2008/09/05 14:14:33 hewitson Exp $

 HISTORY:     22-12-07 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % IPLOT provides an intelligent plotting tool for LTPDA.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: IPLOT provides an intelligent plotting tool for LTPDA.
0005 %
0006 % CALL:               hfig = iplot (a,pl)
0007 %              [hfig, hax] = iplot (a,pl)
0008 %         [hfig, hax, hli] = iplot (a,pl)
0009 %
0010 % INPUTS:      pl   - a parameter list
0011 %              a    - input analysis object
0012 %
0013 % OUTPUTS:     hfig - handles to figures
0014 %              hax  - handles to axes
0015 %              hli  - handles to lines
0016 %
0017 % Plot parameters:
0018 %
0019 %             'Arrangement' - select the plot layout:
0020 %                           'single'   - plots all AOs on individual figures
0021 %                           'stacked'  - plots all AOs on the same axes [default]
0022 %                           'subplots' - plots all AOs on subplots
0023 %
0024 %             'Function'    - specify the plot function:
0025 %                             'plot', 'stairs', 'stem'
0026 %                             [default: 'plot']
0027 %                             *** doesn't work for xyzdata AOs
0028 %
0029 % Line parameters:
0030 %
0031 %        The following properties take cell array values. If the length of
0032 %        the cell array is shorter than the number of lines to plot, the
0033 %        remaining lines will be plotted with the default options. If the
0034 %        cell array is of length 2 and the first cell contains the string
0035 %        'all', then the second cell is used to set the propery of all
0036 %        lines.
0037 %
0038 %             'LineColors' - a cell array of color definitions for each line.
0039 %
0040 %             'LineStyles' - a cell array of line styles.
0041 %
0042 %             'Markers'    - a cell array of markers.
0043 %
0044 %             'LineWidths' - a cell array of line widths. If the length of the
0045 %                            cell array is shorter than the number of lines to
0046 %                            plot, the remaining lines will be plotted with
0047 %                            the default line width.
0048 %
0049 % Axes parameters:
0050 %
0051 %             'Legends' - specify a cell array of strings to be used for
0052 %                         the plot legends. If a cell contains an empty
0053 %                         string, the default legend string is built.
0054 %                         If a single string 'off' is given instead of a
0055 %                         cell array, then the legends are all switched
0056 %                         off.
0057 %
0058 %             'XLabels' - Specify the labels to be used on the x-axis. The
0059 %                         units are added from the data object 'xunits'
0060 %                         property.
0061 %
0062 %             'YLabels' - Specify the labels to be used on the y-axis. The
0063 %                         units are added from the data object 'yunits'
0064 %                         property. If the object contains complex data,
0065 %                         you should specify two y-labels for that object.
0066 %
0067 %    The following axis properties also work with the 'all' keyword as
0068 %    described above in the line properties section.
0069 %
0070 %             'XScales' - Specify the scales to be used on the x-axes.
0071 %
0072 %             'YScales' - Specify the scales to the used on the y-axes. If
0073 %                         an object contains complex data, you should
0074 %                         specify two y-labels for that object.
0075 %
0076 %             'XRanges' - Specify the ranges to be displayed on the x-axes.
0077 %
0078 %             'YRanges' - Specify the ranges to the displayed on the
0079 %                         y-axes.
0080 %
0081 % EXAMPLES:
0082 %
0083 % 1) Plot two time-series AOs with different colors, line styles, and widths
0084 %
0085 %   pl = plist('Linecolors', {'g', 'k'}, 'LineStyles', {'', '--'}, 'LineWidths', {1, 4});
0086 %   iplot(tsao1, tsao2, pl);
0087 %
0088 % 2) Plot two time-series AOs in subplots. Also override the second legend
0089 %    text and the first line style.
0090 %
0091 %   pl = plist('Arrangement', 'subplots', 'LineStyles', {'--'}, 'Legends', {'', 'My Sine Wave'});
0092 %   iplot(tsao1, tsao2, pl);
0093 %
0094 % 3) Plot two time-series AOs taking the square of the y-values of the
0095 %    first AO and the log of the x-values of the second AO.
0096 %
0097 %   pl = plist('Arrangement', 'subplots', 'YMaths', 'y.^2', 'XMaths', {'', 'log(x)'});
0098 %   iplot(tsao1, tsao2, pl);
0099 %
0100 % 4) Plot two frequency-series AOs on subplots with the same Y-scales and
0101 %    Y-ranges
0102 %
0103 %   pl1 = plist('Yscales', {'All', 'lin'});
0104 %   pl2 = plist('arrangement', 'subplots', 'YRanges', {'All', [1e-6 100]});
0105 %   iplot(fsd1, fsd2, pl1, pl2)
0106 %
0107 %
0108 % M-FILE INFO: Get information about this methods by calling
0109 %              >> ao.getInfo('iplot')
0110 %
0111 %              Get information about a specified set-plist by calling:
0112 %              >> ao.getInfo('iplot', 'None')
0113 %
0114 % VERSION:     $Id: iplot.m,v 1.48 2008/09/05 14:14:33 hewitson Exp $
0115 %
0116 % HISTORY:     22-12-07 M Hewitson
0117 %                 Creation
0118 %
0119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0120 
0121 
0122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0123 %
0124 % TODO:
0125 %    1) Add XRange, YRange, ZRange to xyzdata
0126 %    5) How do we deal with axis units? Symbolic math toolbox?
0127 %    7) Should we have a plot_plist field in AO? Then this can be combined
0128 %       with the input plist.
0129 %
0130 
0131 function varargout = iplot(varargin)
0132 
0133   import utils.const.*
0134 
0135   %% Check if this is a call for parameters
0136   if utils.helper.isinfocall(varargin{:})
0137     varargout{1} = getInfo(varargin{3});
0138     return
0139   end
0140 
0141   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0142 
0143   % Collect input variable names
0144   in_names = cell(size(varargin));
0145   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0146 
0147   % Collect all AOs and plists
0148   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0149   [upl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0150 
0151   %% Go through AOs and collect them into similar types
0152 
0153   tsAOs  = [];
0154   fsAOs  = [];
0155   xyAOs  = [];
0156   xyzAOs = [];
0157   cAOs   = [];
0158 
0159   for j=1:numel(as)
0160     switch class(as(j).data)
0161       case 'tsdata'
0162         tsAOs = [tsAOs as(j)];
0163       case 'fsdata'
0164         fsAOs = [fsAOs as(j)];
0165       case 'xydata'
0166         xyAOs = [xyAOs as(j)];
0167       case 'xyzdata'
0168         xyzAOs = [xyzAOs as(j)];
0169       case 'cdata'
0170         cAOs = [cAOs as(j)];
0171       otherwise
0172         warning('!!! Unknown data type %s', class(as(j).data));
0173     end
0174   end
0175 
0176   %% Now plot all the objects on separate figures
0177 
0178   hfig = [];
0179   hax  = [];
0180   hli  = [];
0181 
0182   %----------- TSDATA
0183   if ~isempty(tsAOs)
0184     % get default plist
0185     dpl = getDefaultPlist('Time-series plot');
0186     % combine the plists
0187     pl = combine(upl, dpl);
0188     % Call x-y plot
0189     [hf, ha, hl] = xy_plot(tsAOs, pl);
0190     hfig = [hfig hf];
0191     hax  = [hax ha];
0192     hli  = [hli hl];
0193   end
0194   %----------- XYDATA
0195   if ~isempty(xyAOs)
0196     % get default plist
0197     dpl = getDefaultPlist('X-Y data plot');
0198     % combine the plists
0199     pl = combine(upl, dpl);
0200     % Call x-y plot
0201     [hf, ha, hl] = xy_plot(xyAOs, pl);
0202     hfig = [hfig hf];
0203     hax  = [hax ha];
0204     hli  = [hli hl];
0205   end
0206   %----------- XYZDATA
0207   if ~isempty(xyzAOs)
0208     % get default plist
0209     dpl = getDefaultPlist('3D plot');
0210     % combine the plists
0211     pl = combine(upl, dpl);
0212     % Call x-y-z plot
0213     [hf, ha, hl] = xyz_plot(xyzAOs, pl);
0214     hfig = [hfig hf];
0215     hax  = [hax ha];
0216     hli  = [hli hl];
0217   end
0218   %----------- CDATA
0219   if ~isempty(cAOs)
0220     % get default plist
0221     dpl = getDefaultPlist('Y data plot');
0222     % combine the plists
0223     pl = combine(upl, dpl);
0224     % Call x-y plot
0225     [hf, ha, hl] = y_plot(cAOs, pl);
0226     hfig = [hfig hf];
0227     hax  = [hax ha];
0228     hli  = [hli hl];
0229   end
0230   %----------- FSDATA
0231   if ~isempty(fsAOs)
0232     % get default plist
0233     dpl = getDefaultPlist('Frequency-series plot');
0234     % combine the plists
0235     pl = combine(upl, dpl);
0236     % Call fsdata plot
0237     [hf, ha, hl] = fs_plot(fsAOs, pl);
0238     hfig = [hfig hf];
0239     hax  = [hax ha];
0240     hli  = [hli hl];
0241   end
0242 
0243   %% Deal with outputs
0244   if nargout == 1
0245     varargout{1} = hfig;
0246   end
0247   if nargout == 2
0248     varargout{1} = hfig;
0249     varargout{2} = hax;
0250   end
0251   if nargout == 3
0252     varargout{1} = hfig;
0253     varargout{2} = hax;
0254     varargout{3} = hli;
0255   end
0256 
0257   if nargout > 3
0258     error('### Incorrect number of outputs');
0259   end
0260 
0261 end
0262 
0263 %--------------------------------------------------------------------------
0264 % Plot fsdata objects
0265 %
0266 function varargout = fs_plot(varargin)
0267 
0268   aos = varargin{1};
0269   pl  = varargin{2};
0270 
0271   % Extract parameters
0272   arrangement     = find(pl, 'Arrangement');
0273   colors          = find(pl, 'Colors');
0274   linecolors      = find(pl, 'LineColors');
0275   linestyles      = find(pl, 'LineStyles');
0276   markers         = find(pl, 'Markers');
0277   linewidths      = find(pl, 'LineWidths');
0278   legends         = find(pl, 'Legends');
0279   ylabels         = find(pl, 'YLabels');
0280   xlabels         = find(pl, 'XLabels');
0281   yscales         = find(pl, 'YScales');
0282   xscales         = find(pl, 'XScales');
0283   yranges         = find(pl, 'YRanges');
0284   xranges         = find(pl, 'XRanges');
0285   xmaths          = find(pl, 'XMaths');
0286   ymaths          =  find(pl, 'YMaths');
0287   type            = find(pl, 'Function');
0288   legendLoc       = find(pl, 'LegendLocation');
0289   complexPlotType = find(pl, 'complexPlotType');
0290 
0291   % check whether we want legends or not
0292   if iscell(legends)
0293     legendsOn = 1;
0294   else
0295     if strcmpi(legends, 'off')
0296       legendsOn = 0;
0297     else
0298       legendsOn = 1;
0299       legends = [];
0300     end
0301   end
0302 
0303   if ~iscell(linewidths), linewidths = {linewidths}; end
0304   if ~iscell(linestyles), linestyles = {linestyles}; end
0305   if ~iscell(linecolors), linecolors = {linecolors}; end
0306   if ~iscell(markers), markers = {markers}; end
0307   if ~iscell(legends), legends = {legends}; end
0308   if ~iscell(ylabels), ylabels = {ylabels}; end
0309   if ~iscell(xlabels), xlabels = {xlabels}; end
0310   if ~iscell(xmaths), xmaths = {xmaths}; end
0311   if ~iscell(ymaths), ymaths = {ymaths}; end
0312   if ~iscell(xscales), xscales = {xscales}; end
0313   if ~iscell(yscales), yscales = {yscales}; end
0314   if ~iscell(xranges), xranges = {xranges}; end
0315   if ~iscell(yranges), yranges = {yranges}; end
0316 
0317   % collect figure handles
0318   tsfig = []; tsax  = []; tsli  = [];
0319   % Legend holder
0320   legendStr = [];
0321 
0322   if ~isempty(aos)
0323     % Now loop over AOs
0324     Na = length(aos);
0325     % - first to check if any are complex
0326     haveComplex = 0;
0327     for j=1:Na
0328       y = aos(j).data.y;
0329       ymath = '';
0330       if j<=length(ymaths)
0331         if ~isempty(ymaths{j})
0332           eval(sprintf('y = %s;', ymaths{j}));
0333           ymath = ymaths{j};
0334         end
0335       end
0336       xmath = '';
0337       if j<=length(xmaths)
0338         if ~isempty(xmaths{j})
0339           eval(sprintf('x = %s;', xmaths{j}));
0340           xmath = xmaths{j};
0341         end
0342       end
0343       if ~isreal(y)
0344         haveComplex = 1;
0345       end
0346     end
0347 
0348     % Loop over the AOs now
0349     for j=1:Na
0350       % set real and imag subplot handles to empty
0351       tsax_r = [];
0352       tsax_i = [];
0353       %------- Apply math functions
0354       x = aos(j).data.x;
0355       y = aos(j).data.y;
0356       ymath = '';
0357       if j<=length(ymaths)
0358         if ~isempty(ymaths{j})
0359           eval(sprintf('y = %s;', ymaths{j}));
0360           ymath = ymaths{j};
0361         end
0362       end
0363       xmath = '';
0364       if j<=length(xmaths)
0365         if ~isempty(xmaths{j})
0366           eval(sprintf('x = %s;', xmaths{j}));
0367           xmath = xmaths{j};
0368         end
0369       end
0370       % what figures do we need?
0371       switch arrangement
0372         case 'single'
0373           tsfig = [tsfig figure];
0374           col = colors{1};
0375           % check if this data set is real or complex
0376           if ~isreal(y)
0377             % complex means we use two subplots
0378             tsax_r = subplot(2,1,1);
0379             tsax_i = subplot(2,1,2);
0380             tsax   = [tsax tsax_r tsax_i];
0381           else
0382             % real means we use a single subplot
0383             tsax_r = subplot(1, 1, 1);
0384             tsax = [tsax tsax_r];
0385           end
0386         case 'stacked'
0387           if j==1, tsfig = figure; end
0388           % if at least one of the input fsdata AOs is complex, we need to
0389           % allow for subplots
0390           if haveComplex
0391             tsax_r = subplot(2,1,1);
0392             tsax_i = subplot(2,1,2);
0393             tsax   = [tsax_r tsax_i];
0394           else
0395             tsax_r = subplot(1, 1, 1);
0396             tsax = tsax_r;
0397           end
0398           col = colors{mod(j-1,length(colors))+1};
0399           hold(tsax_r, 'on');
0400           if ishandle(tsax_i)
0401             hold(tsax_i, 'on');
0402           end
0403         case 'subplots'
0404           if j == 1, tsfig = figure; end
0405           c = 1+(j-1)*2;
0406           sx = Na;
0407           sy = 2;
0408           % Now we have one or two subplots per input object.
0409           if ~isreal(y)
0410             tsax_r = subplot(sx, sy,c);
0411             tsax_i = subplot(sx, sy,c+1);
0412             tsax   = [tsax tsax_r tsax_i];
0413           else
0414             tsax_r = subplot(sx, sy, c:c+1);
0415             tsax   = [tsax tsax_r];
0416           end
0417           col = colors{1};
0418         otherwise
0419           error('### Unknown plot arrangement');
0420       end
0421 
0422       %------- Plot the data
0423 
0424       % plot real or complex data and setup default values for scale and
0425       % labels as we go.
0426       if isreal(y)
0427         li   = feval(type, tsax_r, x, y);
0428         tsli = [tsli li];
0429         ylabelr = 'amplitude';
0430         ylabeli = 'imag';
0431         yscaleR = 'log';
0432         yscaleI = 'lin';
0433         xscaleR = 'log';
0434         xscaleI = 'lin';
0435       else
0436         switch complexPlotType
0437           case 'realimag'
0438             li = feval(type, tsax_r, x, y);
0439             li = [li feval(type, tsax_i, x, imag(y))];
0440             tsli = [tsli li];
0441             ylabelr = 'real';
0442             ylabeli = 'imag';
0443             yscaleR = 'lin';
0444             yscaleI = 'lin';
0445             xscaleR = 'lin';
0446             xscaleI = 'lin';
0447           case 'absdeg'
0448             li   = feval(type, tsax_r, x, abs(y));
0449             li   = [li feval(type, tsax_i, x, utils.math.phase(y))];
0450             tsli = [tsli li];
0451             ylabelr = 'amplitude';
0452             ylabeli = 'Phase [deg]';
0453             yscaleR = 'log';
0454             yscaleI = 'lin';
0455             xscaleR = 'log';
0456             xscaleI = 'log';
0457           case 'absrad'
0458             li   = feval(type, tsax_r, x, abs(y));
0459             li   = [li feval(type, tsax_i, x, angle(y))];
0460             tsli = [tsli li];
0461             ylabelr = 'amplitude';
0462             ylabeli = 'phase [rad]';
0463             yscaleR = 'log';
0464             yscaleI = 'lin';
0465             xscaleR = 'log';
0466             xscaleI = 'log';
0467           otherwise
0468             error('### Unknown plot type for complex data');
0469         end
0470       end
0471 
0472       %------- Axis properties
0473 
0474       % Set ylabel
0475       c = 1+(j-1)*2;
0476       if length(ylabels)==2 && strcmpi(ylabels{1}, 'all')
0477         ylstrR = ylabels{2};
0478       elseif c<=length(ylabels)
0479         if ~isempty(ylabels{c})
0480           ylstrR =  ylabels{c};
0481         else
0482           ylstrR = ylabelr;
0483         end
0484       else
0485         ylstrR = ylabelr;
0486       end
0487       if c<length(ylabels)
0488         if ~isempty(ylabels{c+1})
0489           ylstrI =  ylabels{c+1};
0490         else
0491           ylstrI = ylabeli;
0492         end
0493       else
0494         ylstrI = ylabeli;
0495       end
0496       if ~isempty(ymath)
0497         ymath = strrep(ymath, 'y', sprintf('%s', char(aos(j).data.yunits)));
0498         ylstrR = [ylstrR ' ' ymath ];
0499       else
0500         ylstrR = [ylstrR ' ' char(aos(j).data.yunits) ];
0501       end      
0502       ylstrR = fixlabel(ylstrR);      
0503       ylabel(tsax_r, ylstrR);
0504       if ishandle(tsax_i)
0505         ylstrI = fixlabel(ylstrI);
0506         ylabel(tsax_i, ylstrI);
0507       end
0508 
0509       % Set xlabel
0510       if length(xlabels)==2 && strcmpi(xlabels{1}, 'all')
0511         xlstr = xlabels{2};
0512       elseif j<=length(xlabels) && ~isempty(xlabels{j})
0513         xlstr =  xlabels{j};
0514       else
0515         xlstr = find(pl, 'XLabel');
0516       end
0517       if ~isempty(xmath)
0518         xmath = strrep(xmath, 'x', sprintf('%s', char(aos(j).data.xunits)));
0519         xlstr = [xlstr ' ' xmath ];
0520       else
0521         xlstr = [xlstr ' ' char(aos(j).data.xunits) ];
0522       end
0523       xlstr = fixlabel(xlstr);
0524       xlabel(tsax_r, xlstr);
0525       if ishandle(tsax_i)
0526         xlabel(tsax_i, xlstr);
0527       end
0528 
0529       % Set grid on or off
0530       grid(tsax_r, 'on');
0531       if ishandle(tsax_i)
0532         grid(tsax_i, 'on');
0533       end
0534 
0535       % Set Y scale
0536       if length(yscales)==2 && strcmpi(yscales{1}, 'all')
0537         yscaleR = yscales{2};
0538         yscaleI = yscales{2};
0539       else
0540         c = 1+(j-1)*2;
0541         if c<=length(yscales)
0542           if ~isempty(yscales{c})
0543             yscaleR =  yscales{c};
0544           end
0545         end
0546         if c<length(yscales)
0547           if ~isempty(yscales{c+1})
0548             yscaleI =  yscales{c+1};
0549           end
0550         end
0551       end
0552 
0553       set(tsax_r, 'YScale', yscaleR);
0554       if ishandle(tsax_i)
0555         set(tsax_i, 'YScale', yscaleI);
0556       end
0557 
0558       % Set X scale
0559       if length(xscales)==2 && strcmpi(xscales{1}, 'all')
0560         xscaleR = xscales{2};
0561         xscaleI = xscales{2};
0562       else
0563         c = 1+(j-1)*2;
0564         if c<=length(xscales)
0565           if ~isempty(xscales{c})
0566             xscaleR =  xscales{c};
0567           end
0568         end
0569         if c<length(xscales)
0570           if ~isempty(xscales{c+1})
0571             xscaleI =  xscales{c+1};
0572           end
0573         end
0574       end
0575       set(tsax_r, 'XScale', xscaleR);
0576       if ishandle(tsax_i)
0577         set(tsax_i, 'XScale', xscaleI);
0578       end
0579 
0580       % Set Y range
0581       if length(yranges)==2 && strcmpi(yranges{1}, 'all')
0582         set(tsax_r, 'YLim', yranges{2});
0583         if ishandle(tsax_i)
0584           set(tsax_i, 'YLim', yranges{2});
0585         end
0586       else
0587         c = 1+(j-1)*2;
0588         if c<=length(yranges)
0589           if ~isempty(yranges{c})
0590             set(tsax_r, 'YLim', yranges{c});
0591           end
0592         end
0593         if c<length(yranges)
0594           if ~isempty(yranges{c+1})
0595             if ishandle(tsax_i)
0596               set(tsax_i, 'YLim', yranges{c+1});
0597             end
0598           end
0599         end
0600       end
0601 
0602       % Set X range
0603       if length(xranges)==2 && strcmpi(xranges{1}, 'all')
0604         set(tsax_r, 'XLim', xranges{2});
0605         if ishandle(tsax_i)
0606           set(tsax_i, 'XLim', xranges{2});
0607         end
0608       else
0609         c = 1+(j-1)*2;
0610         if c<=length(xranges)
0611           if ~isempty(xranges{c})
0612             set(tsax_r, 'XLim', xranges{c});
0613           end
0614         end
0615         if c<length(xranges)
0616           if ~isempty(xranges{c+1})
0617             if ishandle(tsax_i)
0618               set(tsax_i, 'XLim', xranges{c+1});
0619             end
0620           end
0621         end
0622       end
0623 
0624       %------- line properties
0625 
0626       % Set line color
0627       if isreal(y)
0628         set(li, 'Color', col);
0629       else
0630         set(li, 'Color', col);
0631         set(li, 'Color', col);
0632       end
0633 
0634       % Overide with user colors
0635       if length(linecolors) == 2 && strcmpi(linecolors{1}, 'all')
0636         set(li, 'Color', linecolors{2});
0637       else
0638         if j<=length(linecolors) && ~isempty(linecolors{j})
0639           if isreal(y)
0640             set(li, 'Color', linecolors{j});
0641           else
0642             set(li, 'Color', linecolors{j});
0643             set(li, 'Color', linecolors{j});
0644           end
0645         end
0646       end
0647 
0648       % Set line style
0649       if length(linestyles) == 2 && strcmpi(linestyles{1}, 'all')
0650         set(li, 'LineStyle', linestyles{2});
0651       else
0652         if j<=length(linestyles) && ~isempty(linestyles{j})
0653           if isreal(y)
0654             set(li, 'LineStyle', linestyles{j});
0655           else
0656             set(li, 'LineStyle', linestyles{j});
0657             set(li, 'LineStyle', linestyles{j});
0658           end
0659         end
0660       end
0661 
0662       % Set line widths
0663       if length(linewidths) == 2 && strcmpi(linewidths{1}, 'all')
0664         set(li, 'LineWidth', linewidths{2});
0665       else
0666         if j<=length(linewidths) && ~isempty(linewidths{j})
0667           if isreal(y)
0668             set(li, 'LineWidth', linewidths{j});
0669           else
0670             set(li, 'LineWidth', linewidths{j});
0671             set(li, 'LineWidth', linewidths{j});
0672           end
0673         end
0674       end
0675 
0676       % Set markers
0677       if length(markers) == 2 && strcmpi(markers{1}, 'all')
0678         set(li, 'Marker', markers{2});
0679       else
0680         if j<=length(markers) && ~isempty(markers{j})
0681           if isreal(y)
0682             set(li, 'Marker', markers{j});
0683           else
0684             set(li, 'Marker', markers{j});
0685             set(li, 'Marker', markers{j});
0686           end
0687         end
0688       end
0689 
0690       % Set legend string
0691       lstr = '';
0692       if legendsOn
0693         if j<=length(legends) && ~isempty(legends{j})
0694           lstr = legends{j};
0695         else
0696           lstr = utils.plottools.label(aos(j).name);
0697         end
0698       end
0699       legendStr = [legendStr cellstr(lstr)];
0700 
0701       % Set the legend now if we can
0702       if legendsOn
0703         if strcmp(arrangement, 'single') || strcmp(arrangement, 'subplots')
0704           legend(tsax_r, fixlabel(legendStr{end}), 'Location', legendLoc);
0705         end
0706       end
0707     end % End loop over AOs
0708 
0709     % Process legends for stacked plots
0710     if legendsOn
0711       if strcmp(arrangement, 'stacked')
0712         h = legend(tsax_r, fixlabel(legendStr), 'Location', legendLoc);
0713         set(h, 'FontSize', 10)
0714       end
0715     end
0716   end % End empty AOs
0717 
0718   % Set outputs
0719   if nargout > 0
0720     varargout{1} = tsfig;
0721   end
0722   if nargout > 1
0723     varargout{2} = tsax;
0724   end
0725   if nargout == 3
0726     varargout{3} = tsli;
0727   end
0728   if nargout > 3
0729     error('### Too many output arguments');
0730   end
0731 end % End fs_plot
0732 
0733 %--------------------------------------------------------------------------
0734 % Plot tsdata and xydata objects
0735 %
0736 function varargout = xy_plot(varargin)
0737 
0738   aos = varargin{1};
0739   pl  = varargin{2};
0740 
0741   % Extract parameters
0742   arrangement = find(pl, 'Arrangement');
0743   linecolors  = find(pl, 'LineColors');
0744   colors      = find(pl, 'Colors');
0745   linestyles  = find(pl, 'LineStyles');
0746   markers     = find(pl, 'Markers');
0747   linewidths  = find(pl, 'Line1Widths');
0748   legends     = find(pl, 'Legends');
0749   ylabels     = find(pl, 'YLabels');
0750   xlabels     = find(pl, 'XLabels');
0751   xmaths      = find(pl, 'XMaths');
0752   ymaths      = find(pl, 'YMaths');
0753   yranges     = find(pl, 'YRanges');
0754   xranges     = find(pl, 'XRanges');
0755   yscales     = find(pl, 'YScales');
0756   xscales     = find(pl, 'XScales');
0757   type        = find(pl, 'Function');
0758   legendLoc   = find(pl, 'LegendLocation');
0759 
0760   % check whether we want legends or not
0761   if iscell(legends)
0762     legendsOn = 1;
0763   else
0764     if strcmpi(legends, 'off')
0765       legendsOn = 0;
0766     else
0767       legendsOn = 1;
0768       legends = [];
0769     end
0770   end
0771 
0772   if ~iscell(linewidths), linewidths = {linewidths}; end
0773   if ~iscell(linestyles), linestyles = {linestyles}; end
0774   if ~iscell(linecolors), linecolors = {linecolors}; end
0775   if ~iscell(markers), markers = {markers}; end
0776   if ~iscell(legends), legends = {legends}; end
0777   if ~iscell(ylabels), ylabels = {ylabels}; end
0778   if ~iscell(xlabels), xlabels = {xlabels}; end
0779   if ~iscell(xmaths), xmaths = {xmaths}; end
0780   if ~iscell(ymaths), ymaths = {ymaths}; end
0781   if ~iscell(xranges), xranges = {xranges}; end
0782   if ~iscell(yranges), yranges = {yranges}; end
0783   if ~iscell(xscales), xscales = {xscales}; end
0784   if ~iscell(yscales), yscales = {yscales}; end
0785 
0786   % collect figure handles
0787   tsfig = []; tsax  = []; tsli  = [];
0788   % Legend holder
0789   legendStr = [];
0790   if ~isempty(aos)
0791     % Now loop over AOs to get earliest start time
0792     if strcmp(arrangement, 'stacked')
0793       T0 = 1e50;
0794       Na = length(aos);
0795       for jj=1:Na
0796         % Get this AO
0797         if isa(aos(jj).data, 'tsdata')
0798           if aos(jj).data.t0.utc_epoch_milli/1000 < T0
0799             T0 = floor(aos(jj).data.t0.utc_epoch_milli/1000);
0800           end
0801         end
0802       end
0803     else
0804       T0 = 0;
0805     end
0806 
0807     % Now loop over AOs
0808     Na = length(aos);
0809     for j=1:Na
0810       % Get this AO
0811       toff = 0;
0812       % what figures do we need?
0813       switch arrangement
0814         case 'single'
0815           tsfig = [tsfig figure];
0816           tsax = subplot(1,1,1);
0817           col = colors{1};
0818           if isa(aos(j).data, 'tsdata')
0819             torigin = aos(j).data.t0;
0820           end
0821         case 'stacked'
0822           if j==1, tsfig = figure; end
0823           tsax = subplot(1,1,1);
0824           col = colors{mod(j-1,length(colors))+1};
0825           hold on;
0826           % deal with time-stamps here
0827           if isa(aos(j).data, 'tsdata')
0828             toff = aos(j).data.t0.utc_epoch_milli/1000 - T0;
0829           else
0830             toff = 0;
0831           end
0832           if isa(aos(j).data, 'tsdata')
0833             torigin = time(T0*1000);
0834           end
0835         case 'subplots'
0836           if j == 1, tsfig = figure; end
0837           tsax = [tsax subplot(Na, 1, j)];
0838           col = colors{1};
0839           if isa(aos(j).data, 'tsdata')
0840             torigin = aos(j).data.t0;
0841           end
0842         otherwise
0843           error('### Unknown plot arrangement');
0844       end
0845 
0846       %------- Apply math functions
0847 
0848       % need t0 offset for this time-series
0849       x = aos(j).data.getX + toff;
0850       y = aos(j).data.y;
0851 
0852       ymath = '';
0853       if j<=length(ymaths)
0854         if ~isempty(ymaths{j})
0855           eval(sprintf('y = %s;', ymaths{j}));
0856           ymath = ymaths{j};
0857         end
0858       end
0859       xmath = '';
0860       if j<=length(xmaths)
0861         if ~isempty(xmaths{j})
0862           eval(sprintf('x = %s;', xmaths{j}));
0863           xmath = xmaths{j};
0864         end
0865       end
0866 
0867       %------- Plot the data
0868 
0869       li   = feval(type, tsax(end), x, y);
0870       tsli = [tsli li];
0871       if isa(aos(j).data, 'tsdata')
0872         title(sprintf('Time origin: %s', char(torigin)));
0873       end
0874       %------- Axis properties
0875 
0876       % Set ylabel
0877       if j<=length(ylabels) && ~isempty(ylabels{j})
0878         ylstr =  ylabels{j};
0879       else
0880         ylstr = find(pl, 'YLabel');
0881       end
0882       if ~isempty(ymath)
0883         ymath = strrep(ymath, 'y', sprintf('%s', char(aos(j).data.yunits)));
0884         ylstr = [ylstr ' ' ymath ];
0885       else
0886         ylstr = [ylstr ' ' char(aos(j).data.yunits)];
0887       end
0888       ylstr = fixlabel(ylstr);
0889       ylabel(ylstr);
0890 
0891       % Set xlabel
0892       if j<=length(xlabels) && ~isempty(xlabels{j})
0893         xlstr =  xlabels{j};
0894       else
0895         xlstr = find(pl, 'XLabel');
0896       end
0897       if ~isempty(xmath)
0898         xmath = strrep(xmath, 'x', sprintf('%s', char(aos(j).data.xunits)));
0899         xlstr = [xlstr ' ' xmath  ];
0900       else
0901         xlstr = [xlstr ' ' char(aos(j).data.xunits)  ];
0902       end
0903       xlstr = fixlabel(xlstr);
0904       xlabel(xlstr);
0905 
0906       % Set Y range
0907       if length(yranges) == 2 && strcmpi(yranges{1}, 'all')
0908         set(tsax(end), 'YLim', yranges{2});
0909       else
0910         if j<=length(yranges)
0911           if ~isempty(yranges{j})
0912             set(tsax(end), 'YLim', yranges{j});
0913           end
0914         end
0915       end
0916 
0917       % Set Y scale
0918       yscaleR = 'lin';
0919       if length(yscales)==2 && strcmpi(yscales{1}, 'all')
0920         yscaleR = yscales{2};
0921       else
0922         if j<=length(yscales)
0923           if ~isempty(yscales{j})
0924             yscaleR =  yscales{j};
0925           end
0926         end
0927       end
0928       set(tsax(end), 'YScale', yscaleR);
0929 
0930       % Set X scale
0931       xscaleR = 'lin';
0932       if length(xscales)==2 && strcmpi(xscales{1}, 'all')
0933         xscaleR = xscales{2};
0934       else
0935         if j<=length(xscales)
0936           if ~isempty(xscales{j})
0937             xscaleR =  xscales{j};
0938           end
0939         end
0940       end
0941       set(tsax(end), 'XScale', xscaleR);
0942 
0943       % Set X range
0944       if length(xranges) == 2 && strcmpi(xranges{1}, 'all')
0945         set(tsax(end), 'XLim', xranges{2});
0946       else
0947         if j<=length(xranges)
0948           if ~isempty(xranges{j})
0949             set(tsax(end), 'XLim', xranges{j});
0950           end
0951         end
0952       end
0953 
0954       % Set grid on or off
0955       grid(tsax(end), 'on');
0956 
0957       %------- line properties
0958 
0959       % Set line color
0960       set(li, 'Color', col);
0961 
0962       % Set specific colors
0963       if length(linecolors) == 2 && strcmpi(linecolors{1}, 'all')
0964         set(li, 'Color', linecolors{2});
0965       else
0966         if j<=length(linecolors) && ~isempty(linecolors{j})
0967           set(li, 'Color', linecolors{j});
0968         end
0969       end
0970 
0971       % Set line style
0972       if length(linestyles) == 2 && strcmpi(linestyles{1}, 'all')
0973         set(li, 'LineStyle', linestyles{2});
0974       else
0975         if j<=length(linestyles) && ~isempty(linestyles{j})
0976           set(li, 'LineStyle', linestyles{j});
0977         end
0978       end
0979 
0980       % Set markers
0981       if length(markers) == 2 && strcmpi(markers{1}, 'all')
0982         set(li, 'Marker', markers{2});
0983       else
0984         if j<=length(markers) && ~isempty(markers{j})
0985           set(li, 'Marker', markers{j});
0986         end
0987       end
0988 
0989       % Set line widths
0990       if length(linewidths) == 2 && strcmpi(linewidths{1}, 'all')
0991         set(li, 'LineWidth', linewidths{2});
0992       else
0993         if j<=length(linewidths) && ~isempty(linewidths{j})
0994           set(li, 'LineWidth', linewidths{j});
0995         end
0996       end
0997 
0998       % Set legend string
0999       lstr = '';
1000       if legendsOn
1001         if j<=length(legends) && ~isempty(legends{j})
1002           lstr = legends{j};
1003         else
1004           lstr = utils.plottools.label(aos(j).name);
1005         end
1006       end
1007       legendStr = [legendStr cellstr(lstr)];
1008 
1009       % Set the legend now if we can
1010       if legendsOn
1011         if strcmp(arrangement, 'single') || strcmp(arrangement, 'subplots')
1012           legend(fixlabel(legendStr{end}), 'Location', legendLoc);
1013         end
1014       end
1015     end
1016 
1017     % Process legends for stacked plots
1018     if legendsOn
1019       if strcmp(arrangement, 'stacked')
1020         h = legend(fixlabel(legendStr), 'Location', legendLoc);
1021         set(h, 'FontSize', 10)
1022       end
1023     end
1024   end % End if empty AOs
1025 
1026   % Set outputs
1027   if nargout > 0
1028     varargout{1} = tsfig;
1029   end
1030   if nargout > 1
1031     varargout{2} = tsax;
1032   end
1033   if nargout == 3
1034     varargout{3} = tsli;
1035   end
1036   if nargout > 3
1037     error('### Too many output arguments');
1038   end
1039 end % end xy_plot
1040 
1041 
1042 %--------------------------------------------------------------------------
1043 % Plot cdata objects
1044 %
1045 function varargout = y_plot(varargin)
1046 
1047   aos = varargin{1};
1048   pl  = varargin{2};
1049 
1050   % Extract parameters
1051   arrangement = find(pl, 'Arrangement');
1052   linecolors  = find(pl, 'LineColors');
1053   colors      = find(pl, 'Colors');
1054   linestyles  = find(pl, 'LineStyles');
1055   markers     = find(pl, 'Markers');
1056   linewidths  = find(pl, 'LineWidths');
1057   legends     = find(pl, 'Legends');
1058   ylabels     = find(pl, 'YLabels');
1059   xlabels     = find(pl, 'XLabels');
1060   xmaths      = find(pl, 'XMaths');
1061   ymaths      = find(pl, 'YMaths');
1062   yranges     = find(pl, 'YRanges');
1063   xranges     = find(pl, 'XRanges');
1064   yscales     = find(pl, 'YScales');
1065   xscales     = find(pl, 'XScales');
1066   type        = find(pl, 'Function');
1067   legendLoc   = find(pl, 'LegendLocation');
1068 
1069   if ~iscell(xscales), xscales = {xscales}; end
1070   if ~iscell(yscales), yscales = {yscales}; end
1071 
1072   % check whether we want legends or not
1073   if iscell(legends)
1074     legendsOn = 1;
1075   else
1076     if strcmp(legends, 'off')
1077       legendsOn = 0;
1078     else
1079       legendsOn = 1;
1080       legends = [];
1081     end
1082   end
1083 
1084   if ~iscell(linewidths), linewidths = {linewidths}; end
1085   if ~iscell(linestyles), linestyles = {linestyles}; end
1086   if ~iscell(linecolors), linecolors = {linecolors}; end
1087   if ~iscell(markers), markers = {markers}; end
1088   if ~iscell(legends), legends = {legends}; end
1089   if ~iscell(ylabels), ylabels = {ylabels}; end
1090   if ~iscell(xlabels), xlabels = {xlabels}; end
1091   if ~iscell(xmaths), xmaths = {xmaths}; end
1092   if ~iscell(ymaths), ymaths = {ymaths}; end
1093   if ~iscell(xranges), xranges = {xranges}; end
1094   if ~iscell(yranges), yranges = {yranges}; end
1095 
1096   % collect figure handles
1097   tsfig = []; tsax  = []; tsli  = [];
1098   % Legend holder
1099   legendStr = [];
1100   if ~isempty(aos)
1101     % Now loop over AOs
1102     Na = length(aos);
1103     for j=1:Na
1104       % what figures do we need?
1105       switch arrangement
1106         case 'single'
1107           tsfig = [tsfig figure];
1108           tsax = subplot(1,1,1);
1109           col = colors{1};
1110         case 'stacked'
1111           if j==1, tsfig = figure; end
1112           tsax = subplot(1,1,1);
1113           col = colors{mod(j-1,length(colors))+1};
1114           hold on;
1115         case 'subplots'
1116           if j == 1, tsfig = figure; end
1117           tsax = [tsax subplot(Na, 1, j)];
1118           col = colors{1};
1119         otherwise
1120           error('### Unknown plot arrangement');
1121       end
1122 
1123       %------- Apply math functions
1124       if isreal(aos(j).data.y)
1125         x = 1:length(aos(j).data.y);
1126         y = aos(j).data.y;
1127       else
1128         x = real(aos(j).data.y);
1129         y = imag(aos(j).data.y);
1130       end
1131 
1132       ymath = '';
1133       if j<=length(ymaths)
1134         if ~isempty(ymaths{j})
1135           eval(sprintf('y = %s;', ymaths{j}));
1136           ymath = ymaths{j};
1137         end
1138       end
1139       xmath = '';
1140       if j<=length(xmaths)
1141         if ~isempty(xmaths{j})
1142           eval(sprintf('x = %s;', xmaths{j}));
1143           xmath = xmaths{j};
1144         end
1145       end
1146 
1147       %------- Plot the data
1148 
1149       idcs = feval(type, tsax(end), x, y);
1150       tsli = [tsli idcs(1:end).'];
1151 
1152       %------- Axis properties
1153 
1154       % Set ylabel
1155       if j<=length(ylabels) && ~isempty(ylabels{j})
1156         ylstr =  ylabels{j};
1157       else
1158         ylstr = find(pl, 'YLabel');
1159       end
1160       if ~isempty(ymath)
1161         ymath = strrep(ymath, 'y', sprintf('%s', char(aos(j).data.yunits)));
1162         ylstr = [ylstr ' ' ymath ];
1163       else
1164         ylstr = [ylstr ' ' char(aos(j).data.yunits) ];
1165       end
1166       ylstr = fixlabel(ylstr);
1167       ylabel(ylstr);
1168 
1169       % Set xlabel
1170       if j<=length(xlabels) && ~isempty(xlabels{j})
1171         xlstr =  xlabels{j};
1172       else
1173         xlstr = find(pl, 'XLabel');
1174       end
1175       if ~isempty(xmath)
1176         xmath = strrep(xmath, 'x', 'N');
1177         xlstr = [xlstr ' ' xmath ];
1178       else
1179         xlstr = [xlstr ' [N]' ];
1180       end
1181       xlstr = fixlabel(xlstr);
1182       xlabel(xlstr);
1183 
1184       % Set Y scale
1185       yscaleR = 'lin';
1186       if length(yscales)==2 && strcmpi(yscales{1}, 'all')
1187         yscaleR = yscales{2};
1188       else
1189         if j<=length(yscales)
1190           if ~isempty(yscales{j})
1191             yscaleR =  yscales{j};
1192           end
1193         end
1194       end
1195       set(tsax(end), 'YScale', yscaleR);
1196 
1197       % Set X scale
1198       xscaleR = 'lin';
1199       if length(xscales)==2 && strcmpi(xscales{1}, 'all')
1200         xscaleR = xscales{2};
1201       else
1202         if j<=length(xscales)
1203           if ~isempty(xscales{j})
1204             xscaleR =  xscales{j};
1205           end
1206         end
1207       end
1208       set(tsax(end), 'XScale', xscaleR);
1209 
1210       % Set Y range
1211       if length(yranges) == 2 && strcmpi(yranges{1}, 'all')
1212         set(tsax(end), 'YLim', yranges{2});
1213       else
1214         if j<=length(yranges)
1215           if ~isempty(yranges{j})
1216             set(tsax(end), 'YLim', yranges{j});
1217           end
1218         end
1219       end
1220 
1221       % Set X range
1222       if length(xranges) == 2 && strcmpi(xranges{1}, 'all')
1223         set(tsax(end), 'XLim', xranges{2});
1224       else
1225         if j<=length(xranges)
1226           if ~isempty(xranges{j})
1227             set(tsax(end), 'XLim', xranges{j});
1228           end
1229         end
1230       end
1231 
1232       % Set grid on or off
1233       grid(tsax(end), 'on');
1234 
1235       %------- line properties
1236 
1237       % Set line color
1238       set(idcs, 'Color', col);
1239 
1240       % Overide line colors with user defined colors
1241       if length(linecolors) == 2 && strcmpi(linecolors{1}, 'all')
1242         set(idcs, 'Color', linecolors{2});
1243       else
1244         if j<=length(linecolors) && ~isempty(linecolors{j})
1245           set(idcs, 'Color', linecolors{j});
1246         end
1247       end
1248 
1249       % Set line style
1250       if length(linestyles) == 2 && strcmpi(linestyles{1}, 'all')
1251         set(idcs, 'LineStyle', linestyles{2});
1252       else
1253         if j<=length(linestyles) && ~isempty(linestyles{j})
1254           set(idcs, 'LineStyle', linestyles{j});
1255         end
1256       end
1257 
1258       % Set Markers
1259       if length(markers) == 2 && strcmpi(markers{1}, 'all')
1260         set(idcs, 'Marker', markers{2});
1261       else
1262         if j<=length(markers) && ~isempty(markers{j})
1263           set(idcs, 'Marker', markers{j});
1264         end
1265       end
1266 
1267       % Set line widths
1268       if length(linewidths) == 2 && strcmpi(linewidths{1}, 'all')
1269         set(idcs, 'LineWidth', linewidths{2});
1270       else
1271         if j<=length(linewidths) && ~isempty(linewidths{j})
1272           set(idcs, 'LineWidth', linewidths{j});
1273         end
1274       end
1275 
1276       % Set legend string
1277       if legendsOn
1278         if j<=length(legends) && ~isempty(legends{j})
1279           legendStr = [legendStr legends(j)];
1280         else
1281           lstr = utils.plottools.label(aos(j).name);
1282           legendStr = [legendStr cellstr(lstr)];
1283         end
1284       end
1285 
1286       % Set the legend now if we can
1287       if legendsOn
1288         if strcmp(arrangement, 'single') || strcmp(arrangement, 'subplots')
1289           legend(fixlabel(legendStr{end}), 'Location', legendLoc);
1290         end
1291       end
1292     end
1293 
1294     % Process legends for stacked plots
1295     if legendsOn
1296       if strcmp(arrangement, 'stacked')
1297         h = legend(fixlabel(legendStr), 'Location', legendLoc);
1298         set(h, 'FontSize', 10)
1299       end
1300     end
1301 
1302   end
1303 
1304   % Set outputs
1305   if nargout > 0
1306     varargout{1} = tsfig;
1307   end
1308   if nargout > 1
1309     varargout{2} = tsax;
1310   end
1311   if nargout == 3
1312     varargout{3} = tsli;
1313   end
1314   if nargout > 3
1315     error('### Too many output arguments');
1316   end
1317 end % End y_plot
1318 
1319 %--------------------------------------------------------------------------
1320 % Plot xyzdata objects
1321 %
1322 function varargout = xyz_plot(varargin)
1323 
1324   aos = varargin{1};
1325   pl  = varargin{2};
1326 
1327   % Extract parameters
1328   arrangement = find(pl, 'Arrangement');
1329   linecolors  = find(pl, 'LineColors');
1330   colors      = find(pl, 'Colors');
1331   linestyles  = find(pl, 'LineStyles');
1332   linewidths  = find(pl, 'LineWidths');
1333   legends     = find(pl, 'Legends');
1334   zlabels     = find(pl, 'ZLabels');
1335   ylabels     = find(pl, 'YLabels');
1336   xlabels     = find(pl, 'XLabels');
1337   xmaths      = find(pl, 'XMaths');
1338   ymaths      = find(pl, 'YMaths');
1339   zmaths      = find(pl, 'ZMaths');
1340   legendLoc   = find(pl, 'LegendLocation');
1341 
1342   % check whether we want legends or not
1343   if iscell(legends)
1344     legendsOn = 1;
1345   else
1346     if strcmp(legends, 'off')
1347       legendsOn = 0;
1348     else
1349       legendsOn = 1;
1350       legends = [];
1351     end
1352   end
1353 
1354   % collect figure handles
1355   tsfig = [];
1356   tsax  = [];
1357   tsli  = [];
1358 
1359   % Legend holder
1360   legendStr = [];
1361 
1362   if ~isempty(aos)
1363 
1364     % Now loop over AOs
1365     Na = length(aos);
1366     for j=1:Na
1367       % what figures do we need?
1368       switch arrangement
1369         case 'single'
1370           tsfig = [tsfig figure];
1371           tsax = subplot(1,1,1);
1372         case 'subplots'
1373           if j == 1, tsfig = figure; end
1374           tsax = [tsax subplot(Na, 1, j)];
1375         otherwise
1376           error('### Unknown plot arrangement');
1377       end
1378 
1379       %------- Apply math functions
1380       x = aos(j).data.x;
1381       y = aos(j).data.y;
1382       z = aos(j).data.z;
1383 
1384       ymath = '';
1385       if j<=length(ymaths)
1386         if ~isempty(ymaths{j})
1387           eval(sprintf('y = %s;', ymaths{j}));
1388           ymath = ymaths{j};
1389         end
1390       end
1391       xmath = '';
1392       if j<=length(xmaths)
1393         if ~isempty(xmaths{j})
1394           eval(sprintf('x = %s;', xmaths{j}));
1395           xmath = xmaths{j};
1396         end
1397       end
1398       zmath = '';
1399       if j<=length(zmaths)
1400         if ~isempty(zmaths{j})
1401           eval(sprintf('z = %s;', zmaths{j}));
1402           zmath = zmaths{j};
1403         end
1404       end
1405 
1406       %------- Plot the data
1407 
1408       idcs = pcolor(x,y,z);
1409       tsli = [tsli idcs(1:end).'];
1410 
1411       % plot properties
1412       set(idcs, 'EdgeColor', 'none');
1413 
1414       %------- Axis properties
1415 
1416       % Reverse y-direction for spectrograms
1417       set(tsax(end), 'YDir', 'reverse');
1418 
1419       % Set ylabel
1420       if j<=length(ylabels) && ~isempty(ylabels{j})
1421         ylstr =  ylabels{j};
1422       else
1423         ylstr = find(pl, 'YLabel');
1424       end
1425       if ~isempty(ymath)
1426         ymath = strrep(ymath, 'y', sprintf('%s', char(aos(j).data.yunits)));
1427         ylstr = [ylstr ' ' ymath ];
1428       else
1429         ylstr = [ylstr ' ' char(aos(j).data.yunits) ];
1430       end
1431       ylstr = fixlabel(ylstr);
1432       ylabel(ylstr);
1433 
1434       % Set xlabel
1435       if j<=length(xlabels) && ~isempty(xlabels{j})
1436         xlstr =  xlabels{j};
1437       else
1438         xlstr = find(pl, 'XLabel');
1439       end
1440       if ~isempty(xmath)
1441         xmath = strrep(xmath, 'x', sprintf('%s', char(aos(j).data.xunits)));
1442         xlstr = [xlstr ' ' xmath ];
1443       else
1444         xlstr = [xlstr ' ' char(aos(j).data.xunits) ];
1445       end
1446       xlstr = fixlabel(xlstr);
1447       xlabel(xlstr);
1448 
1449       % Set grid on or off
1450       grid(tsax(end), 'on');
1451 
1452       % Set title string
1453       if ~strcmpi(legends, 'off')
1454         if j<=length(legends) && ~isempty(legends{j})
1455           legendStr = [legendStr legends(j)];
1456         else
1457           lstr = utils.plottools.label(aos(j).name);
1458           legendStr = [legendStr cellstr(lstr)];
1459         end
1460       end
1461 
1462       % Set the legend now if we can
1463       tstr = legendStr{end};
1464       if legendsOn
1465         title(tstr);
1466       end
1467 
1468       % Set colorbars
1469       hc = colorbar('peer', tsax(end));
1470       if j<=length(zlabels)
1471         if ~isempty(zlabels{j})
1472           zlstr = zlabels{j};
1473         end
1474       else
1475         zlstr = find(pl, 'Zlabel');
1476       end
1477       if ~isempty(zmath), zlstr = [zlstr sprintf('\n%s', zmath)]; end
1478       ylh = get(hc, 'YLabel');
1479       set(ylh, 'String', zlstr);
1480       set(ylh, 'Fontsize', get(tsax(end), 'Fontsize'))
1481       set(ylh, 'FontName', get(tsax(end), 'FontName'))
1482       set(ylh, 'FontAngle', get(tsax(end), 'FontAngle'))
1483       set(ylh, 'FontWeight', get(tsax(end), 'FontWeight'))
1484     end
1485   end
1486 
1487   % Set outputs
1488   if nargout > 0
1489     varargout{1} = tsfig;
1490   end
1491   if nargout > 1
1492     varargout{2} = tsax;
1493   end
1494   if nargout == 3
1495     varargout{3} = tsli;
1496   end
1497   if nargout > 3
1498     error('### Too many output arguments');
1499   end
1500 end % end xyz_plot
1501 
1502 %--------------------------------------------------------------------------
1503 % Get Info Object
1504 %--------------------------------------------------------------------------
1505 function ii = getInfo(varargin)
1506   if nargin == 1 && strcmpi(varargin{1}, 'None')
1507     sets = {};
1508     pl   = [];
1509   elseif nargin == 1&& ~isempty(varargin{1}) && ischar(varargin{1})
1510     sets{1} = varargin{1};
1511     pl = getDefaultPlist(sets{1});
1512   else
1513     sets = {'Time-series plot', 'Frequency-series plot', 'Y data plot', 'X-Y data plot', '3D plot'};
1514     % get plists
1515     pl(size(sets)) = plist;
1516     for k = 1:numel(sets)
1517       pl(k) =  getDefaultPlist(sets{k});
1518     end
1519   end
1520   % Build info object
1521   ii = minfo(mfilename, 'ao', '', utils.const.categories.output, '$Id: iplot.m,v 1.48 2008/09/05 14:14:33 hewitson Exp $', sets, pl);
1522 end
1523 
1524 %--------------------------------------------------------------------------
1525 % Get Default Plist
1526 %--------------------------------------------------------------------------
1527 function out = getDefaultPlist(set)
1528 
1529   % Get the LTPDA color set for lines
1530   colors = getappdata(0,'ltpda_default_plot_colors');
1531 
1532   out = plist(...
1533     'Colors', colors, ...
1534     'Arrangement', 'stacked', ...
1535     'Function', 'plot', 'LegendLocation', 'Best');
1536 
1537   switch set
1538     case 'Frequency-series plot'
1539       out.append(...
1540         'complexPlotType', 'absdeg', ...
1541         'XLabel', 'Frequency');
1542     case 'Time-series plot'
1543       out.append(...
1544         'Xlabel', 'Time', ...
1545         'Ylabel', 'Amplitude');
1546     case 'X-Y data plot'
1547       out.append(...
1548         'Xlabel', 'X-data', ...
1549         'Ylabel', 'Y-data', ...
1550         'YMaths', '', ...
1551         'XMaths', '');
1552     case '3D plot'
1553       out = plist(...
1554         'Colors', colors,...
1555         'Arrangement', 'single', ...
1556         'Xlabel', 'Time', ...
1557         'Ylabel', 'Frequency',...
1558         'Zlabel', 'Amplitude', ...
1559         'YMaths', '', ...
1560         'ZMaths', '', ...
1561         'XMaths', '');
1562     case 'Y data plot'
1563       out.append(...
1564         'Xlabel', 'Index', ...
1565         'Ylabel', 'Value');
1566     otherwise
1567       out = plist();
1568   end
1569 end
1570 
1571 % Perform some substitutions on the labels
1572 function ss = fixlabel(ss)
1573 
1574   wasCell = true;
1575   if ~iscell(ss)
1576     ss = {ss};
1577     wasCell = false;
1578   end
1579 
1580   for kk=1:numel(ss)
1581     s = ss{kk};
1582   
1583     % Replace all ^(...) with ^{...}
1584     j = 1;
1585     while j<numel(s)
1586       if strcmp(s(j:j+1), '^(')
1587         % find next )
1588         for k=1:numel(s)-j+1
1589           if s(j+k) == ')'
1590             s(j+1) = '{';
1591             s(j+k) = '}';
1592             break;
1593           end
1594         end
1595       end
1596       j = j + 1;
1597     end
1598     % Replace all .^ with ^
1599     s = strrep(s, '.^', '^');
1600 
1601     ss(kk) = {s};
1602   end
1603 
1604 
1605   if ~wasCell
1606     ss = ss{1};
1607   end
1608   
1609 end

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003