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.7 2007/10/24 17:35:28 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.7 2007/10/24 17:35:28 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 VERSION = '$Id: find.m,v 1.7 2007/10/24 17:35:28 ingo Exp $';
0027 
0028 %% Check if this is a call for parameters
0029 if nargin == 2
0030   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0031     in = char(varargin{2});
0032     if strcmp(in, 'Params')
0033       bo = getDefaultPL();
0034       return
0035     elseif strcmp(in, 'Version')
0036       bo = VERSION;
0037       return
0038     end
0039   end
0040 end
0041 
0042 %% capture input variable names
0043 invars = {};
0044 for j=1:nargin
0045   if isa(varargin{j}, 'ao')
0046     invars = [invars cellstr(inputname(j))];
0047   end
0048 end
0049 
0050 ALGONAME = mfilename;
0051 VERSION  = '$Id: find.m,v 1.7 2007/10/24 17:35:28 ingo Exp $';
0052 
0053 % Get inputs
0054 as      = [];
0055 ps      = [];
0056 queries = [];
0057 for j=1:nargin
0058   if isa(varargin{j}, 'ao')
0059     as = [as varargin{j}];
0060   end
0061   if isa(varargin{j}, 'plist')
0062     ps = [ps varargin{j}];
0063   end
0064   if ischar(varargin{j})
0065     queries = [queries ' & ' varargin{j}];
0066   end
0067 end
0068 
0069 Na = length(as);
0070 if isempty(as)
0071   error('### Please input at least one AO.');
0072 end
0073 if isempty(ps) && isempty(queries)
0074   error('### Please specify queries to select directly or as a plist.');
0075 end
0076 
0077 % Combine plists
0078 if ~isempty(ps)
0079   pl = combine(ps);
0080 else
0081   pl = plist();
0082 end
0083 
0084 % Get sample selection from plist
0085 queries = [queries ' & ' find(pl, 'queries')];
0086 
0087 % We may have pre or trailing '&' now
0088 queries = strtrim(queries);
0089 if queries(1) == '&'
0090   queries = queries(2:end);
0091 end
0092 if queries(end) == '&'
0093   queries = queries(1:end-1);
0094 end
0095 
0096 
0097 disp(sprintf('*** processing %s', queries));
0098 
0099 % Loop over input AOs
0100 bo = [];
0101 for j=1:numel(as)
0102 
0103   a = as(j);
0104   d = a.data;
0105 
0106   [x,y] = get_xy_values(d);
0107 
0108   % special case for the cdata class.
0109   % The user can also use the query to 'vals'
0110   vals = y;
0111 
0112   cmd = sprintf('idx = find(%s);', queries);
0113   try
0114     eval(cmd);
0115   catch
0116     l_error = lasterror;
0117     error('%s\n\n### please use x or y for the queries.',l_error.message);
0118   end
0119 
0120   if isa(d, 'cdata')
0121     % Have each input of 'vals' a 'tags'
0122     if length(x) == length(y)
0123       d = set_xy_axis(d, x(idx), y(idx));
0124     else
0125       d = set_xy_axis(d, x, y(idx));
0126     end
0127   else
0128     d = set_xy_axis(d, x(idx), y(idx));
0129   end
0130 
0131   % Make output AO
0132 
0133   % create new output history
0134   h = history(ALGONAME, VERSION, plist(param('queries', queries)), a.hist);
0135   h = set(h, 'invars', invars);
0136 
0137   % make output analysis object
0138   b = ao(d, h);
0139 
0140   % set name
0141   % name for this object
0142   if j > length(invars)
0143     n1 = a.name;
0144   else
0145     n1 = invars{j};
0146   end
0147   b = set(b, 'name', sprintf('select(%s)', n1));
0148 
0149   % Add to output array
0150   bo = [bo b];
0151 
0152 end
0153 
0154 % Reshape the ouput to the same size of the input
0155 bo = reshape(bo, size(as));
0156 
0157 
0158 %% Get default params
0159 function pl_default = getDefaultPL()
0160 
0161   pl_default = plist(param('query',  ''));
0162 
0163 
0164 
0165 % END

Generated on Thu 01-Nov-2007 09:42:34 by m2html © 2003