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.10 2007/07/18 13:58:44 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.10 2007/07/18 13:58:44 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 %% Check if this is a call for parameters
0027 if nargin == 2
0028   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0029     in = char(varargin{2});
0030     if strcmp(in, 'Params')
0031       bo = getDefaultPL();
0032       return
0033     end
0034   end
0035 end
0036 
0037 % capture input variable names
0038 invars = {};
0039 for j=1:nargin
0040   if isa(varargin{j}, 'ao')
0041     invars = [invars cellstr(inputname(j))];
0042   end
0043 end
0044 
0045 ALGONAME = mfilename;
0046 VERSION  = '$Id: select.m,v 1.10 2007/07/18 13:58:44 ingo Exp $';
0047 
0048 % Get inputs
0049 as      = [];
0050 ps      = [];
0051 samples = [];
0052 for j=1:nargin
0053   if isa(varargin{j}, 'ao')
0054     as = [as varargin{j}];
0055   end
0056   if isa(varargin{j}, 'plist')
0057     ps = [ps varargin{j}];
0058   end
0059   if isnumeric(varargin{j})
0060     samples = [samples varargin{j}];
0061   end
0062 end
0063 
0064 Na = length(as);
0065 if isempty(as)
0066   error('### Please input at least one AO.');
0067 end
0068 if isempty(ps) && isempty(samples)
0069   error('### Please specify samples to select directly or as a plist.');
0070 end
0071 
0072 % Combine plists
0073 if ~isempty(ps)
0074   pl = combine(ps);
0075 else
0076   pl = plist();
0077 end
0078 
0079 % Get sample selection from plist
0080 samples = [samples find(pl, 'samples')];
0081 
0082 % Loop over input AOs
0083 bo = [];
0084 for j=1:Na
0085 
0086   a = as(j);
0087   d = a.data;
0088 
0089   [x,y] = get_xy_axis(d);
0090 
0091   if isa(d, 'cdata')
0092     if length(d.tags) == length(d.vals)
0093       d = set_xy_axis(d, x(samples), y(samples));
0094     else
0095       d = set_xy_axis(d, x, y(samples));
0096     end
0097   else
0098     d = set_xy_axis(d, x(samples), y(samples));
0099   end
0100 
0101 %   if isa(d, 'tsdata')
0102 %     d = set(d, 't', d.t(samples));
0103 %     d = set(d, 'x', d.x(samples));
0104 %   elseif isa(d, 'fsdata')
0105 %     d = set(d, 'f',  d.f(samples));
0106 %     d = set(d, 'xx', d.xx(samples));
0107 %
0108 %   elseif isa(d, 'cdata')
0109 %     if ndims(d.vals) <= 2
0110 %       d = set(d, 'tags', d.tags(samples));
0111 %     end
0112 %     d = set(d, 'vals', d.vals(samples));
0113 %
0114 %   elseif isa(d, 'xydata')
0115 %     d = set(d, 'x', d.x(samples));
0116 %     d = set(d, 'y', d.y(samples));
0117 %
0118 %   else
0119 %     error('### Unknown data type in AO.');
0120 %   end
0121 
0122   % Make output AO
0123 
0124   % create new output history
0125   h = history(ALGONAME, VERSION, plist(param('samples', samples)), a.hist);
0126   h = set(h, 'invars', invars);
0127 
0128   % make output analysis object
0129   b = ao(d, h);
0130 
0131   % set name
0132   % name for this object
0133   if isempty(invars{j})
0134     n1 = a.name;
0135   else
0136     n1 = invars{j};
0137   end
0138   b = set(b, 'name', sprintf('select(%s)', n1));
0139 
0140   % Add to output array
0141   bo = [bo b];
0142 
0143 end
0144 
0145 % Get default params
0146 function plo = getDefaultPL()
0147 
0148 disp('* creating default plist...');
0149 plo = plist();
0150 plo = append(plo, param('samples', []));
0151 disp('* done.');
0152 
0153 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003