Home > atmlab > handy > rqre_gridmatch.m

rqre_gridmatch

PURPOSE ^

RQRE_GRIDMATCH Checks that length of grid matches data

SYNOPSIS ^

function rqre_gridmatch( A, dim, g, varargin )

DESCRIPTION ^

 RQRE_GRIDMATCH   Checks that length of grid matches data

    Grid lengths of both 0 and 1 are accpeted for singleton dimensions.

    Issues an error if criterion not fulfilled.

    The function can also be used to check if grid stricltly ascending or
    descending.

 FORMAT   rqre_gridmatch( A, dim, g, [, demand_sorted,reversed] ) 
        
 IN    A     Gridded data.
       dim   Dimension for *g*.
       g     Grid.
 OPT   demand_sorted   Flag to demand that grid is sorted, without 
                       any points duplicated.
       reversed        Flag to indicate that grid is supposed to descending
                       (instead of ascending).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rqre_gridmatch.m

SOURCE CODE ^

0001 % RQRE_GRIDMATCH   Checks that length of grid matches data
0002 %
0003 %    Grid lengths of both 0 and 1 are accpeted for singleton dimensions.
0004 %
0005 %    Issues an error if criterion not fulfilled.
0006 %
0007 %    The function can also be used to check if grid stricltly ascending or
0008 %    descending.
0009 %
0010 % FORMAT   rqre_gridmatch( A, dim, g, [, demand_sorted,reversed] )
0011 %
0012 % IN    A     Gridded data.
0013 %       dim   Dimension for *g*.
0014 %       g     Grid.
0015 % OPT   demand_sorted   Flag to demand that grid is sorted, without
0016 %                       any points duplicated.
0017 %       reversed        Flag to indicate that grid is supposed to descending
0018 %                       (instead of ascending).
0019 
0020 % 2010-01-04   Created by Patrick Eriksson.
0021 
0022 function rqre_gridmatch( A, dim, g, varargin )
0023 %
0024 [demand_sorted,reversed] = optargs( varargin, {false,false} );
0025 
0026 assert( iswhole( dim ) );                                                   %&%
0027 assert( istensor1( g ) );                                                   %&%
0028 assert( isboolean( demand_sorted ) );                                       %&%
0029 assert( isboolean( reversed ) );                                            %&%
0030                                                                             
0031 l = size(A,dim);
0032 
0033 if (l>1 & length(g)~=l) | (l<2 & length(g)>1) 
0034   error( 'Length of grid does not match size of *%s* for dimension %d.', ...
0035                                                         inputname(1), dim );
0036 end
0037 
0038 
0039 if demand_sorted
0040   if reversed
0041     g = g(end:-1:1);
0042     if min( diff(g) <= 0 ) 
0043       error( 'The grid must be sorted in descending order.' );
0044     end
0045   else
0046     if min( diff(g) <= 0 ) 
0047       error( 'The grid must be sorted in ascending order.' );
0048     end
0049   end
0050 end
0051 
0052

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