Assigns named arguments passed to your function (as in plot(), etc.) to local variables. The name of the argument is the name of the local variable in your function.
Example: inputfun('prompt', '>', 'defval', 5.1, 'timeout', 5);
Really simple and easy to use; other implementations of this idea on File Exchange require a lot of overhead to set this up, where as my code just requires one extra function call near the top of your function.
Usage:
(1) in your function, define vars with default values;
(2) call procArgs(varargin)
Minimal error checking: requires that all passed variable names match already defined variables in your function. It would be pretty easy to add type checking if you wanted it (I don't, particularly).
Example:
%% example function using procargs
function test(varargin)
name = 'John';
age = 32;
procArgs(varargin)
fprintf('name=%s, age=%i\n', name, age);
%% example calls
test('name', 'Amber'); % prints Amber, 32
test('age', 99); % prints John, 99
test('Ages', 0); % error, will report that Ages is not defined.
|