Home > atmlab > collocations > collocation_restrain.m

collocation_restrain

PURPOSE ^

collocation_restrain Find rows fulfilling restrictions

SYNOPSIS ^

function rows = collocation_restrain(data, varargin)

DESCRIPTION ^

 collocation_restrain Find rows fulfilling restrictions

 Find row numbers were certain limitations in the data are met.

 IN

   data    matrix      As produced by collocation_read
   ranges  Nx3 matrix  Matrix containing rows [colno min max], where data
                       rows from the data are selected if
                       min <= data(row, col) <= max.
                       Defaults to [] (do nothing)
   filters cell array  FIXME DOC

 OUT

   rows    logical     Rows where limitations are met

 See also: limstruct2limmat

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

collocation_restrain.m

SOURCE CODE ^

0001 function rows = collocation_restrain(data, varargin)
0002 
0003 % collocation_restrain Find rows fulfilling restrictions
0004 %
0005 % Find row numbers were certain limitations in the data are met.
0006 %
0007 % IN
0008 %
0009 %   data    matrix      As produced by collocation_read
0010 %   ranges  Nx3 matrix  Matrix containing rows [colno min max], where data
0011 %                       rows from the data are selected if
0012 %                       min <= data(row, col) <= max.
0013 %                       Defaults to [] (do nothing)
0014 %   filters cell array  FIXME DOC
0015 %
0016 % OUT
0017 %
0018 %   rows    logical     Rows where limitations are met
0019 %
0020 % See also: limstruct2limmat
0021 %
0022 % $Id$
0023 
0024 [ranges, filters] = optargs(varargin, {[], {}});
0025 
0026 if isempty(ranges)
0027     rows = true(size(data, 1), 1);
0028 else
0029     rightrange = all(data(:, ranges(:, 1)) >= repmat(ranges(:, 2)', [size(data, 1) 1]), 2) & ...
0030         all(data(:, ranges(:, 1)) <= repmat(ranges(:, 3)', [size(data, 1) 1]), 2);
0031     
0032     rows = rightrange;
0033     logtext(atmlab('OUT'), 'Selecting ranges: %d -> %d\n', ...
0034         size(data, 1), sum(rows));
0035 end
0036 
0037 if ~any(rows)
0038     logtext(atmlab('OUT'), 'No more collocations, nothing to do\n');
0039     return
0040 end
0041     
0042 for k = 1:length(filters)
0043     % make a cell array of column vectors so that I can pass a
0044     % variable number of arguments to the filter
0045     filter = filters{k}{1};
0046     args = cellfun(@(v) data(:, v), ...
0047         filters{k}{2}, ...
0048         'UniformOutput', false);
0049     if length(filters{k}) > 2
0050         addargs = filters{k}{3};
0051     else
0052         addargs = {};
0053     end
0054     try
0055         lim = filter(args{:}, addargs{:});
0056     catch ME
0057         switch ME.identifier
0058             case 'atmlab:granule_first_line'
0059                 logtext(atmlab('ERR'), ...
0060                     'WARNING! Could not filter %s! ERROR ''%s''!\n', ...
0061                     func2str(filter), ME.message);
0062                 continue;
0063             otherwise
0064                 ME.rethrow();
0065         end
0066     end
0067         
0068     logtext(atmlab('OUT'), ...
0069         'filter %s: %d -> %d collocations\n', func2str(filter), ...
0070         sum(rows), sum(rows&lim));
0071     rows = rows&lim;
0072 end
0073 
0074 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005