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.15 2007/11/26 14:48:13 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.15 2007/11/26 14:48:13 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.15 2007/11/26 14:48:13 ingo Exp $';
0028 samples  = [];
0029 
0030 %% Check if this is a call for parameters
0031 if nargin == 2
0032   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0033     in = char(varargin{2});
0034     if strcmp(in, 'Params')
0035       bo = getDefaultPL();
0036       return
0037     elseif strcmp(in, 'Version')
0038       bo = VERSION;
0039       return
0040     end
0041   end
0042 end
0043 
0044 %% Collect input ao's, plist's and ao variable names
0045 in_names = {};
0046 for ii = 1:nargin
0047   in_names{end+1} = inputname(ii);
0048 
0049   if isnumeric(varargin{ii})
0050     samples = [samples varargin{ii}];
0051   end
0052 end
0053 
0054 [as, ps, invars] = collect_inputs(varargin, in_names);
0055 
0056 if isempty(as)
0057   error('### Please input at least one AO.');
0058 end
0059 if isempty(ps) && isempty(samples)
0060   error('### Please specify samples to select directly or as a plist.');
0061 end
0062 
0063 % Combine plists
0064 if ~isempty(ps)
0065   pl = combine(ps);
0066 else
0067   pl = plist();
0068 end
0069 
0070 % Get sample selection from plist
0071 samples = [samples find(pl, 'samples')];
0072 
0073 % Loop over input AOs
0074 bo = [];
0075 for j=1:numel(as)
0076 
0077   a = as(j);
0078   d = a.data;
0079 
0080   [x,y] = get_xy_values(d);
0081 
0082   if isa(d, 'cdata')
0083     if length(d.x) == length(d.y)
0084       d = set_xy_axis(d, x(samples), y(samples));
0085     else
0086       d = set_xy_axis(d, x, y(samples));
0087     end
0088   else
0089     d = set_xy_axis(d, x(samples), y(samples));
0090   end
0091 
0092   % Make output AO
0093 
0094   % create new output history
0095   h = history(ALGONAME, VERSION, plist(param('samples', samples)), a.hist);
0096   h = set(h, 'invars', invars(j));
0097 
0098   % make output analysis object
0099   b = ao(d, h);
0100 
0101   % set name
0102   % name for this object
0103   b = setnh(b, 'name', sprintf('select(%s)', invars{j}));
0104 
0105   % Add to output array
0106   bo = [bo b];
0107 
0108 end
0109 
0110 % Reshape the ouput to the same size of the input
0111 bo = reshape(bo, size(as));
0112 
0113 % Get default params
0114 function plo = getDefaultPL()
0115 
0116 plo = plist();
0117 plo = append(plo, param('samples', []));
0118 
0119 % END

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003