Home > classes > @ao > find.m

find

PURPOSE ^

FIND particular samples that satisfy the input query and return a new AO.

SYNOPSIS ^

function bo = find(varargin)

DESCRIPTION ^

 FIND particular samples that satisfy the input query and return a new AO.

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

 DESCRIPTION: FIND particular samples that satisfy the input query and return a new AO.

 CALL:        b = find(a, 'x > 10 & x < 100')
              b = find(a, plist)

 PARAMETERS:  query - a string specifying a query on 'x' or 'y' for axes data
                      or 'vals' for cdata

 VERSION:     $Id: find.m,v 1.5 2007/07/11 16:01:24 ingo Exp $

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

 >> pl = find(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 = find(varargin)
0002 % FIND particular samples that satisfy the input query and return a new AO.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: FIND particular samples that satisfy the input query and return a new AO.
0007 %
0008 % CALL:        b = find(a, 'x > 10 & x < 100')
0009 %              b = find(a, plist)
0010 %
0011 % PARAMETERS:  query - a string specifying a query on 'x' or 'y' for axes data
0012 %                      or 'vals' for cdata
0013 %
0014 % VERSION:     $Id: find.m,v 1.5 2007/07/11 16:01:24 ingo Exp $
0015 %
0016 % The following call returns a parameter list object that contains the
0017 % default parameter values:
0018 %
0019 % >> pl = find(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: find.m,v 1.5 2007/07/11 16:01:24 ingo Exp $';
0047 
0048 % Get inputs
0049 as      = [];
0050 ps      = [];
0051 queries = [];
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 ischar(varargin{j})
0060     queries = [queries ' & ' 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(queries)
0069   error('### Please specify queries 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 queries = [queries ' & ' find(pl, 'queries')];
0081 
0082 % We may have pre or trailing '&' now
0083 queries = strtrim(queries);
0084 if queries(1) == '&'
0085   queries = queries(2:end);
0086 end
0087 if queries(end) == '&'
0088   queries = queries(1:end-1);
0089 end
0090 
0091 
0092 disp(sprintf('*** processing %s', queries));
0093 
0094 % Loop over input AOs
0095 bo = [];
0096 for j=1:Na
0097 
0098   a = as(j);
0099   d = a.data;
0100 
0101   [x,y] = get_xy_axis(d);
0102 
0103   % special case for the cdata class.
0104   % The user can also use the query to 'vals'
0105   vals = y;
0106 
0107   cmd = sprintf('idx = find(%s);', queries);
0108   try
0109     eval(cmd);
0110   catch
0111     l_error = lasterror;
0112     error('%s\n\n### please use x or y for the queries.',l_error.message);
0113   end
0114 
0115   if isa(d, 'cdata')
0116     % Have each input of 'vals' a 'tags'
0117     if length(x) == length(y)
0118       d = set_xy_axis(d, x(idx), y(idx));
0119     else
0120       d = set_xy_axis(d, x, y(idx));
0121     end
0122   else
0123     d = set_xy_axis(d, x(idx), y(idx));
0124   end
0125 
0126   % Make output AO
0127 
0128   % create new output history
0129   h = history(ALGONAME, VERSION, plist(param('queries', queries)), a.hist);
0130   h = set(h, 'invars', invars);
0131 
0132   % make output analysis object
0133   b = ao(d, h);
0134 
0135   % set name
0136   % name for this object
0137   if isempty(invars{j})
0138     n1 = a.name;
0139   else
0140     n1 = invars{j};
0141   end
0142   b = set(b, 'name', sprintf('select(%s)', n1));
0143 
0144   % Add to output array
0145   bo = [bo b];
0146 
0147 end
0148 
0149 %% Get default params
0150 function pl_default = getDefaultPL()
0151 
0152 disp('* creating default plist...');
0153   pl_default = plist(param('query',  ''));
0154 disp('* done.');
0155 
0156 
0157 
0158 % END

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