SETARGS | Parse user-specified optional arguments (varargin) with default values

버전 2.0.0.0 (1.85 KB) 작성자: Bob Spunt
Assigning values (default vs. user) to optional arguments (varargin) in a function
다운로드 수: 348
업데이트 날짜: 2016/10/31

This is a utility for setting the value of optional arguments to a function. The first argument is required and should be a cell array of "name, default value" pairs for all optional arguments. The second argument is optional and should be a cell array of "name, custom value"pairs for at least one of the optional arguments.
USAGE: argstruct = setargs(defaultargs, varargs)

---
OUTPUT

ARGSTRUCT
structure containing the final argument values

---
INPUTS

DEFAULTARGS
cell array of "'Name', value" pairs for all variables with default values

VARARGS [optional]
cell array of user-specified "'Name', value" pairs for one or more of the variables with default values. this will typically be the "varargin" cell array. for each pair, SETARGS determines if the specified variable name can be uniquely matched to one of the default variable names specified in DEFAULTARGS. matching uses STRNCMPI and thus is case-insensitive and open to partial name matches (e.g., default variable name 'FontWeight' would be matched by 'fontweight', 'Fontw', etc.). if a match is found, the user-specified value is then used in place of the default value. if no match is found or if multiple matches are found, SETARGS returns an error and displays in the command window information about the argument that caused the problem.

---
USAGE EXAMPLE (TO BE USED AT TOP OF FUNCTION WITH VARARGIN)

defaultargs = {'arg1', 0, 'arg2', 'words', 'arg3', rand};
argstruct = setargs(defaultargs, varargin)

인용 양식

Bob Spunt (2024). SETARGS | Parse user-specified optional arguments (varargin) with default values (https://github.com/spunt/setargs), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2014b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

GitHub 디폴트 브랜치를 사용하는 버전은 다운로드할 수 없음

버전 게시됨 릴리스 정보
2.0.0.0

Updated documentation and variable names and clarified content of error messages

1.0.0.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.