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

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003