


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
M-FILE INFO: Get information about this methods by calling
>> ao.getInfo('find')
Get information about a specified set-plist by calling:
>> ao.getInfo('find', 'None')
VERSION: $Id: find.m,v 1.22 2008/09/05 11:05:29 ingo Exp $
HISTORY: 14-05-07 M Hewitson
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


0001 % FIND particular samples that satisfy the input query and return a new AO. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: FIND particular samples that satisfy the input query and return a new AO. 0005 % 0006 % CALL: b = find(a, 'x > 10 & x < 100') 0007 % b = find(a, plist) 0008 % 0009 % PARAMETERS: query - a string specifying a query on 'x' or 'y' for axes data 0010 % or 'vals' for cdata 0011 % 0012 % M-FILE INFO: Get information about this methods by calling 0013 % >> ao.getInfo('find') 0014 % 0015 % Get information about a specified set-plist by calling: 0016 % >> ao.getInfo('find', 'None') 0017 % 0018 % VERSION: $Id: find.m,v 1.22 2008/09/05 11:05:29 ingo Exp $ 0019 % 0020 % HISTORY: 14-05-07 M Hewitson 0021 % Creation 0022 % 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0024 0025 function varargout = find(varargin) 0026 0027 % Check if this is a call for parameters 0028 if utils.helper.isinfocall(varargin{:}) 0029 varargout{1} = getInfo(varargin{3}); 0030 return 0031 end 0032 0033 import utils.const.* 0034 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0035 0036 % Collect input variable names 0037 in_names = cell(size(varargin)); 0038 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0039 0040 % Collect all AOs and plists 0041 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0042 [pl, pl_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0043 0044 % Decide on a deep copy or a modify 0045 bs = copy(as, nargout); 0046 0047 % combine plists 0048 pl = combine(pl, getDefaultPlist()); 0049 0050 % initialise queries 0051 queries = ''; 0052 % extract any from inputs 0053 for j=1:numel(rest) 0054 if ischar(rest{j}) 0055 queries = [queries ' & ' rest{j}]; 0056 end 0057 end 0058 0059 % Get sample selection from plist 0060 queries = [queries ' & ' find(pl, 'query')]; 0061 0062 % We may have pre or trailing '&' now 0063 queries = strtrim(queries); 0064 if queries(1) == '&' 0065 queries = queries(2:end); 0066 end 0067 if queries(end) == '&' 0068 queries = queries(1:end-1); 0069 end 0070 0071 % Loop over input AOs 0072 for j=1:numel(bs) 0073 0074 % The user uses the variables x and y so we need 0075 % to put them in the workspace. 0076 x = bs(j).data.getX; 0077 y = bs(j).data.getY; 0078 0079 idx = []; 0080 cmd = sprintf('idx = find(%s);', queries); 0081 try 0082 eval(cmd); 0083 catch ME 0084 error('%s\n\n### please use x or y for the queries.',ME.message); 0085 end 0086 0087 % set data 0088 bs(j).data.setXY(x(idx), y(idx)); 0089 0090 if isa(bs(j).data, 'tsdata') 0091 % Check fs and see if is x evenly sampled? 0092 [fs,t0,fitted] = tsdata.fitfs(x(idx)); 0093 if fitted 0094 bs(j).data.setXY(x(idx), y(idx)); 0095 bs(j).data.setFs(fs); 0096 else 0097 % drop x 0098 bs(j).data.setY(y(idx)); 0099 bs(j).data.collapseX; 0100 end 0101 end 0102 0103 % set name 0104 bs(j).setName(sprintf('select(%s)', ao_invars{j}), 'internal'); 0105 % add history 0106 bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist); 0107 end 0108 0109 % Set output 0110 varargout{1} = bs; 0111 end 0112 0113 %-------------------------------------------------------------------------- 0114 % Get Info Object 0115 %-------------------------------------------------------------------------- 0116 function ii = getInfo(varargin) 0117 if nargin == 1 && strcmpi(varargin{1}, 'None') 0118 sets = {}; 0119 pls = []; 0120 else 0121 sets = {'Default'}; 0122 pls = getDefaultPlist; 0123 end 0124 % Build info object 0125 ii = minfo(mfilename, 'ao', '', utils.const.categories.helper, '$Id: find.m,v 1.22 2008/09/05 11:05:29 ingo Exp $', sets, pls); 0126 end 0127 0128 %-------------------------------------------------------------------------- 0129 % Get Default Plist 0130 %-------------------------------------------------------------------------- 0131 function pl_default = getDefaultPlist() 0132 pl_default = plist('query', ''); 0133 end 0134 0135