getargs

PURPOSE ^

Utility to process parameter name/value pairs.

SYNOPSIS ^

function [emsg,varargout]=getargs(pnames,dflts,varargin)

DESCRIPTION ^

 Utility to process parameter name/value pairs.

 Based on code fromt the Matlab Statistics Toolobox "private/statgetargs.m"

 [EMSG,A,B,...]=GETARGS(PNAMES,DFLTS,'NAME1',VAL1,'NAME2',VAL2,...) accepts a cell
 array PNAMES of valid parameter names, a cell array DFLTS of default values for the
 parameters named in PNAMES, and additional parameter name/value pairs.  Returns
 parameter values A,B,... in the same order as the names in PNAMES.  Outputs
 corresponding to entries in PNAMES that are not specified in the name/value pairs are
 set to the corresponding value from DFLTS.  If nargout is equal to length(PNAMES)+1,
 then unrecognized name/value pairs are an error.  If nargout is equal to
 length(PNAMES)+2, then all unrecognized name/value pairs are returned in a single cell
 array following any other outputs.

 EMSG is empty if the arguments are valid, or the text of an error message if an error
 occurs.  GETARGS does not actually throw any errors, but rather returns an error
 message so that the caller may throw the error. Outputs will be partially processed
 after an error occurs.

 EXAMPLE
   pnames = {'color' 'linestyle', 'linewidth'}
   dflts  = {    'r'         '_'          '1'}
   v = {'linew' 2 'nonesuch' [1 2 3] 'linestyle' ':'};
   [emsg,color,linestyle,linewidth,unrec] = getargs(pnames,dflts,v{:}) % ok
   [emsg,color,linestyle,linewidth] = getargs(pnames,dflts,v{:})    % error

 DATESTAMP
   29-Sep-2005  2:00pm

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
Generated on Wed 03-May-2006 23:48:50 by m2html © 2003