Home > classes > @ao > select.m

select

PURPOSE ^

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

SYNOPSIS ^

function bo = select(varargin)

DESCRIPTION ^

 SELECT particular samples from the input AOs and return new AOs with only
 those samples.
 
 Usage: b = select(a, [1 2 3 4]);
        b = select(a, pl)
 
 Parameters:
   'samples'  - a list of samples to select
 
 M Hewitson 14-05-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bo = select(varargin)
0002 
0003 % SELECT particular samples from the input AOs and return new AOs with only
0004 % those samples.
0005 %
0006 % Usage: b = select(a, [1 2 3 4]);
0007 %        b = select(a, pl)
0008 %
0009 % Parameters:
0010 %   'samples'  - a list of samples to select
0011 %
0012 % M Hewitson 14-05-07
0013 %
0014 %
0015 
0016 % capture input variable names
0017 invars = {};
0018 for j=1:nargin
0019   if isa(varargin{j}, 'ao')
0020     invars = [invars cellstr(inputname(j))];
0021   end
0022 end
0023 
0024 ALGONAME = mfilename;
0025 VERSION  = '$Id: select.html,v 1.1 2007/06/08 14:15:03 hewitson Exp $';
0026 
0027 % Get inputs
0028 as      = [];
0029 ps      = [];
0030 samples = [];
0031 for j=1:nargin
0032   if isa(varargin{j}, 'ao')
0033     as = [as varargin{j}];
0034   end
0035   if isa(varargin{j}, 'plist')
0036     ps = [ps varargin{j}];
0037   end
0038   if isnumeric(varargin{j})
0039     samples = [samples varargin{j}];
0040   end
0041 end
0042 
0043 Na = length(as);
0044 if isempty(as)
0045   error('### Please input at least one AO.');
0046 end
0047 if isempty(ps) && isempty(samples)
0048   error('### Please specify samples to select directly or as a plist.');
0049 end
0050 
0051 % Combine plists
0052 if ~isempty(ps)
0053   pl = combine(ps);
0054 else
0055   pl = plist();
0056 end
0057 
0058 % Get sample selection from plist
0059 samples = [samples find(pl, 'samples')];
0060   
0061 % Loop over input AOs
0062 bo = [];
0063 for j=1:Na
0064 
0065   a = as(j);
0066   d = a.data;
0067   
0068   if isa(d, 'tsdata')
0069     t = d.t;
0070     x = d.x;
0071     d = set(d, 't', d.t(samples));
0072     d = set(d, 'x', d.x(samples));
0073   elseif isa(d, 'fsdata')
0074     f  = d.f;
0075     xx = d.xx;
0076     d = set(d, 'f', f(samples));
0077     d = set(d, 'xx', xx(samples));
0078     
0079   elseif isa(d, 'cdata')
0080     if ndims(d.vals) <= 2
0081       d = set(d, 'tags', d.tags(samples));
0082     end
0083     d = set(d, 'vals', d.vals(samples));
0084     
0085   elseif isa(d, 'xydata')
0086     x = d.x;
0087     y = d.y;
0088     d = set(d, 'x', x(samples));
0089     d = set(d, 'y', y(samples));
0090     
0091   else
0092     error('### Unknown data type in AO.');
0093   end  
0094   
0095   % Make output AO
0096   
0097   % create new output history
0098   h = history(ALGONAME, VERSION, plist(param('samples', samples)), a.hist);
0099   h = set(h, 'invars', invars);
0100 
0101   % make output analysis object
0102   b = ao(d, h);
0103 
0104   % set name
0105   % name for this object
0106   if isempty(invars{j})
0107     n1 = a.name;
0108   else
0109     n1 = invars{j};
0110   end
0111   b = set(b, 'name', sprintf('select(%s)', n1));
0112 
0113   % Add to output array
0114   bo = [bo b];
0115   
0116 end
0117 
0118 % END

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003