Parse function arguments

버전 1.0.0.0 (1.91 KB) 작성자: Aslak Grinsted
A useful tool for parsing function arguments like 'cellspacing',6,'monkey',1
다운로드 수: 5.5K
업데이트 날짜: 2004/10/27

라이선스 없음

Helper function for parsing varargin. Makes it easy to write functions that take arguments like this: subaxis(4,2,1,'spacing',0,'marginleft',.1,'H','pt',.1)


ArgStruct=parseArgs(varargin,ArgStruct[,FlagtypeParams[,Aliases]])

* ArgStruct is the structure full of named arguments with default values.
* Flagtype params is params that don't require a value. (the value will be set to 1 if it is present)
* Aliases can be used to map one argument-name to several argstruct fields


example usage:
--------------
function parseargtest(varargin)

%define the acceptable named arguments and assign default values
Args=struct('Holdaxis',0, ...
'SpacingVertical',0.05,'SpacingHorizontal',0.05, ...
'PaddingLeft',0,'PaddingRight',0,'PaddingTop',0,'PaddingBottom',0, ...
'MarginLeft',.1,'MarginRight',.1,'MarginTop',.1,'MarginBottom',.1, ...
'rows',[],'cols',[]);

%The capital letters define abrreviations.
% Eg. parseargtest('spacingvertical',0) is equivalent to parseargtest('sv',0)

Args=parseArgs(varargin,Args, ... % fill the arg-struct with values entered by the user
{'Holdaxis'}, ... %this argument has no value (flag-type)
{'Spacing' {'sh','sv'}; 'Padding' {'pl','pr','pt','pb'}; 'Margin' {'ml','mr','mt','mb'}});

disp(Args)

인용 양식

Aslak Grinsted (2024). Parse function arguments (https://www.mathworks.com/matlabcentral/fileexchange/3448-parse-function-arguments), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R12
모든 릴리스와 호환
플랫폼 호환성
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!
버전 게시됨 릴리스 정보
1.0.0.0

Improved flag parameter functionality.