Easy-to-use interface for converting parameter-value pairs into variables within a function. Unlike inputParser and other typical parameter-value parsers, easyparse is able to (and by default does) directly create variables within the called function, rather than as fields of a struct.
- To create variables in the function workspace according to varargin consisting of parameter-value pairs, use this syntax in your function:
easyparse(varargin);
- To create only variables with allowed_names, create a cell array of allowed names and use this syntax:
easyparse(varargin, allowed_names);
- To create a struct with fields specified by the names in varargin, (similar to the output of inputParser) ask for an output argument:
s = easyparse(...);
As an example, let's say you wanted a function, epdemo, that took inputs 'blee', 'bloo', and 'blah'. Then epdemo would be called with in the typical parameter value manner:
epdemo('blee', 1:10, 'blah', 4, 'bloo', 0);
To parse these inputs within epdemo requires a single line:
function epdemo(varargin)
easyparse(varargin,{'blee','bloo','blah'});
foo = blee*100;
bar = bloo - blah;
...
end
CAVEAT UTILITOR: this function relies on assignin statements. Input checking is performed to limit potential damage, but use at your own risk.
One of a series of simple functions to provide easier input parsing within MATLAB.
引用
Jared (2024). easyparse (https://www.mathworks.com/matlabcentral/fileexchange/39772-easyparse), MATLAB Central File Exchange. 取得済み .
MATLAB リリースの互換性
プラットフォームの互換性
Windows macOS Linuxカテゴリ
タグ
謝辞
ヒントを得たファイル: Parse function arguments, parse_pv_pairs, parseargs: Simplifies input processing for functions with multiple options
ヒントを与えたファイル: SETARGS | Parse user-specified optional arguments (varargin) with default values, easydefaults
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!バージョン | 公開済み | リリース ノート | |
---|---|---|---|
1.7.0.0 | Improved input checks: now, easyparse warns you that it will not parse variables with names identical to already-defined functions to avoid unintended results. |
||
1.6.0.0 | Typo fixed. |
||
1.5.0.0 | Typo fixed. |
||
1.4.0.0 | Typo fixed. |
||
1.3.0.0 | Typo fixed. |
||
1.2.0.0 | Added demo to description. |
||
1.0.0.0 |