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.html,v 1.14 2008/03/31 10:27:32 hewitson Exp $

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

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

 The following call returns a string that contains the routine CVS version:

 >> version = select(ao,'Version')

 The following call returns a string that contains the routine category:

 >> category = select(ao,'Category')

 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.html,v 1.14 2008/03/31 10:27:32 hewitson 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 % The following call returns a string that contains the routine CVS version:
0022 %
0023 % >> version = select(ao,'Version')
0024 %
0025 % The following call returns a string that contains the routine category:
0026 %
0027 % >> category = select(ao,'Category')
0028 %
0029 % HISTORY: 14-05-07 M Hewitson
0030 %             Creation
0031 %
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 
0034 ALGONAME = mfilename;
0035 VERSION  = '$Id: select.html,v 1.14 2008/03/31 10:27:32 hewitson Exp $';
0036 CATEGORY = 'Signal Processing';
0037 
0038 samples  = [];
0039 
0040 %% Check if this is a call for parameters
0041 if nargin == 2
0042   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0043     in = char(varargin{2});
0044     if strcmp(in, 'Params')
0045       bo = getDefaultPL();
0046       return
0047     elseif strcmp(in, 'Version')
0048       bo = VERSION;
0049       return
0050     elseif strcmp(in, 'Category')
0051       bo = CATEGORY;
0052       return
0053     end
0054   end
0055 end
0056 
0057 %% Collect input ao's, plist's and ao variable names
0058 in_names = {};
0059 for ii = 1:nargin
0060   in_names{end+1} = inputname(ii);
0061 
0062   if isnumeric(varargin{ii})
0063     samples = [samples varargin{ii}];
0064   end
0065 end
0066 
0067 [as, ps, invars] = collect_inputs(varargin, in_names);
0068 
0069 if isempty(as)
0070   error('### Please input at least one AO.');
0071 end
0072 if isempty(ps) && isempty(samples)
0073   error('### Please specify samples to select directly or as a plist.');
0074 end
0075 
0076 % Combine plists
0077 if ~isempty(ps)
0078   pl = combine(ps);
0079 else
0080   pl = plist();
0081 end
0082 
0083 % Get sample selection from plist
0084 samples = [samples find(pl, 'samples')];
0085 
0086 % Loop over input AOs
0087 bo = [];
0088 for j=1:numel(as)
0089 
0090   a = as(j);
0091   d = a.data;
0092 
0093   [x,y] = get_xy_values(d);
0094 
0095   if isa(d, 'cdata')
0096     if length(d.x) == length(d.y)
0097       d = set_xy_axis(d, x(samples), y(samples));
0098     else
0099       d = set_xy_axis(d, x, y(samples));
0100     end
0101   else
0102     d = set_xy_axis(d, x(samples), y(samples));
0103   end
0104 
0105   % Make output AO
0106 
0107   % create new output history
0108   h = history(ALGONAME, VERSION, plist(param('samples', samples)), a.hist);
0109   h = set(h, 'invars', invars(j));
0110 
0111   % make output analysis object
0112   b = ao(d, h);
0113 
0114   % set name
0115   % name for this object
0116   b = setnh(b, 'name', sprintf('select(%s)', invars{j}));
0117 
0118   % Add to output array
0119   bo = [bo b];
0120 
0121 end
0122 
0123 % Reshape the ouput to the same size of the input
0124 bo = reshape(bo, size(as));
0125 
0126 % Get default params
0127 function plo = getDefaultPL()
0128 
0129 plo = plist();
0130 plo = append(plo, param('samples', []));
0131 
0132 % END

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003