Home > classes > @ao > select.m

select

PURPOSE ^

SELECT select particular samples from the input AOs and return new AOs with only those samples.

SYNOPSIS ^

function bo = select(varargin)

DESCRIPTION ^

 SELECT select particular samples from the input AOs and return new AOs with only those samples.

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

 DESCRIPTION: SELECT select particular samples from the input AOs and return
              new AOs with only those samples.

 CALL:        b = select(a, [1 2 3 4]);
              b = select(a, pl)

 Parameters: 'samples'  - a list of samples to select

 VERSION:     $Id: select.m,v 1.12 2007/11/02 12:26:24 ingo Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = select(ao, 'Params')

 HISTORY: 14-05-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function bo = select(varargin)
0002 % SELECT select particular samples from the input AOs and return new AOs with only those samples.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SELECT select particular samples from the input AOs and return
0007 %              new AOs with only those samples.
0008 %
0009 % CALL:        b = select(a, [1 2 3 4]);
0010 %              b = select(a, pl)
0011 %
0012 % Parameters: 'samples'  - a list of samples to select
0013 %
0014 % VERSION:     $Id: select.m,v 1.12 2007/11/02 12:26:24 ingo Exp $
0015 %
0016 % The following call returns a parameter list object that contains the
0017 % default parameter values:
0018 %
0019 % >> pl = select(ao, 'Params')
0020 %
0021 % HISTORY: 14-05-07 M Hewitson
0022 %             Creation
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 ALGONAME = mfilename;
0027 VERSION  = '$Id: select.m,v 1.12 2007/11/02 12:26:24 ingo Exp $';
0028 
0029 %% Check if this is a call for parameters
0030 if nargin == 2
0031   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0032     in = char(varargin{2});
0033     if strcmp(in, 'Params')
0034       bo = getDefaultPL();
0035       return
0036     elseif strcmp(in, 'Version')
0037       bo = VERSION;
0038       return
0039     end
0040   end
0041 end
0042 
0043 % capture input variable names
0044 invars = {};
0045 for j=1:nargin
0046   if isa(varargin{j}, 'ao')
0047     invars = [invars cellstr(inputname(j))];
0048   end
0049 end
0050 
0051 % Get inputs
0052 as      = [];
0053 ps      = [];
0054 samples = [];
0055 for j=1:nargin
0056   if isa(varargin{j}, 'ao')
0057     as = [as varargin{j}];
0058   end
0059   if isa(varargin{j}, 'plist')
0060     ps = [ps varargin{j}];
0061   end
0062   if isnumeric(varargin{j})
0063     samples = [samples varargin{j}];
0064   end
0065 end
0066 
0067 if isempty(as)
0068   error('### Please input at least one AO.');
0069 end
0070 if isempty(ps) && isempty(samples)
0071   error('### Please specify samples to select directly or as a plist.');
0072 end
0073 
0074 % Combine plists
0075 if ~isempty(ps)
0076   pl = combine(ps);
0077 else
0078   pl = plist();
0079 end
0080 
0081 % Get sample selection from plist
0082 samples = [samples find(pl, 'samples')];
0083 
0084 % Loop over input AOs
0085 bo = [];
0086 for j=1:numel(as)
0087 
0088   a = as(j);
0089   d = a.data;
0090 
0091   [x,y] = get_xy_values(d);
0092 
0093   if isa(d, 'cdata')
0094     if length(d.tags) == length(d.vals)
0095       d = set_xy_axis(d, x(samples), y(samples));
0096     else
0097       d = set_xy_axis(d, x, y(samples));
0098     end
0099   else
0100     d = set_xy_axis(d, x(samples), y(samples));
0101   end
0102 
0103   % Make output AO
0104 
0105   % create new output history
0106   h = history(ALGONAME, VERSION, plist(param('samples', samples)), a.hist);
0107   h = set(h, 'invars', invars);
0108 
0109   % make output analysis object
0110   b = ao(d, h);
0111 
0112   % set name
0113   % name for this object
0114   if j > length(invars)
0115     n1 = a.name;
0116   else
0117     n1 = invars{j};
0118   end
0119   b = setnh(b, 'name', sprintf('select(%s)', n1));
0120 
0121   % Add to output array
0122   bo = [bo b];
0123 
0124 end
0125 
0126 % Reshape the ouput to the same size of the input
0127 bo = reshape(bo, size(as));
0128 
0129 % Get default params
0130 function plo = getDefaultPL()
0131 
0132 plo = plist();
0133 plo = append(plo, param('samples', []));
0134 
0135 % END

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003