


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.html,v 1.15 2008/03/31 10:27:32 hewitson Exp $
The following call returns a parameter list object that contains the
default parameter values:
>> pl = find(ao, 'Params')
The following call returns a string that contains the routine CVS version:
>> version = find(ao,'Version')
The following call returns a string that contains the routine category:
>> category = find(ao,'Category')
HISTORY: 14-05-07 M Hewitson
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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