SORT the values in the AO. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SORT sorts the values in the input data. CALL: ao_out = sort(ao_in); ao_out = sort(ao1, pl1, ao_vector, ao_matrix, pl2); PARAMETERS: 'dim' - sort along the specified dimension: 'x' or 'y' [default: 'y'] 'dir' - select direction of sort: 'ascend' or 'descend' [default: 'ascend'] M-FILE INFO: Get information about this methods by calling >> ao.getInfo('sort') Get information about a specified set-plist by calling: >> ao.getInfo('sort', 'None') VERSION: $Id: sort.m,v 1.10 2008/09/05 11:15:19 ingo Exp $ HISTORY: 27-05-2008 Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % SORT the values in the AO. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: SORT sorts the values in the input data. 0005 % 0006 % CALL: ao_out = sort(ao_in); 0007 % ao_out = sort(ao1, pl1, ao_vector, ao_matrix, pl2); 0008 % 0009 % PARAMETERS: 0010 % 0011 % 'dim' - sort along the specified dimension: 'x' or 'y' 0012 % [default: 'y'] 0013 % 'dir' - select direction of sort: 'ascend' or 'descend' 0014 % [default: 'ascend'] 0015 % 0016 % M-FILE INFO: Get information about this methods by calling 0017 % >> ao.getInfo('sort') 0018 % 0019 % Get information about a specified set-plist by calling: 0020 % >> ao.getInfo('sort', 'None') 0021 % 0022 % VERSION: $Id: sort.m,v 1.10 2008/09/05 11:15:19 ingo Exp $ 0023 % 0024 % HISTORY: 27-05-2008 Hewitson 0025 % Creation 0026 % 0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0028 0029 function varargout = sort (varargin) 0030 0031 % Check if this is a call for parameters 0032 if utils.helper.isinfocall(varargin{:}) 0033 varargout{1} = getInfo(varargin{3}); 0034 return 0035 end 0036 0037 import utils.const.* 0038 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0039 0040 % Collect input variable names 0041 in_names = cell(size(varargin)); 0042 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0043 0044 % Collect all AOs 0045 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0046 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0047 0048 % Decide on a deep copy or a modify 0049 bs = copy(as, nargout); 0050 0051 % Combine plists 0052 pl = combine(pl, getDefaultPlist); 0053 0054 % Get parameters 0055 sdir = find(pl, 'dir'); 0056 dim = find(pl, 'dim'); 0057 0058 %% go through analysis objects 0059 for j=1:numel(bs) 0060 % Sort values 0061 switch dim 0062 case 'x' 0063 [mx, idx] = sort(bs(j).data.getX, 1, sdir); 0064 my = bs(j).data.y(idx); 0065 case 'y' 0066 [my, idx] = sort(bs(j).data.y, 1, sdir); 0067 mx = bs(j).data.getX(idx); 0068 otherwise 0069 error('### can''t sort along dimension ''%s''.', dim); 0070 end 0071 % set new data 0072 bs(j).setXY(mx,my, 'internal'); 0073 % set data name 0074 bs(j).setName(sprintf('sort(%s)', ao_invars{j}), 'internal'); 0075 % Add history 0076 bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist); 0077 end 0078 0079 % Reshape the ouput to the same size of the input 0080 if nargout > 0 0081 varargout{1} = bs; 0082 end 0083 end 0084 0085 %-------------------------------------------------------------------------- 0086 % Get Info Object 0087 %-------------------------------------------------------------------------- 0088 function ii = getInfo(varargin) 0089 if nargin == 1 && strcmpi(varargin{1}, 'None') 0090 sets = {}; 0091 pl = []; 0092 else 0093 sets = {'Default'}; 0094 pl = getDefaultPlist; 0095 end 0096 % Build info object 0097 ii = minfo(mfilename, 'ao', '', utils.const.categories.op, '$Id: sort.m,v 1.10 2008/09/05 11:15:19 ingo Exp $', sets, pl); 0098 end 0099 0100 %-------------------------------------------------------------------------- 0101 % Get Default Plist 0102 %-------------------------------------------------------------------------- 0103 function pl_default = getDefaultPlist() 0104 pl_default = plist('dim', 'y', 'dir', 'ascend'); 0105 end 0106 0107 % END