loadOptions

版本 1.0.0.0 (1.9 KB) 作者: Nathaniel Brahms
Tool for implementing option name/value pairs in function arguments
922.0 次下载
更新时间 2007/12/4

无许可证

Often one desires to write a function that takes a large number of optional arguments. One way to do this is to allow for an arbitrary number of option name-value pairs in the function argument:

function r = f(a,b,c,name1,value1,...)

This method has the advantages of:

1) Allowing those using the function to specify options without needing to check the position of the option in a long list of arguments.

2) Allowing for options to have default values that need not be specified each function call.

3) Eliminates the need to deal with empty values passed for unspecified options.

loadOptions is an easy-to-use function designed to aide in writing functions taking option name/value pairs. It converts the list of name/value pairs into an easily usable options struct (a la optimset). It allows for option defaults.

And, unlike typical MATLAB syntax, the user may specify data types for each option value, or leave data types untyped, or have some values typed and others untyped.

Please see the help text / example for details on how to use loadOptions when writing a function.

loadOptions was written and tested in R2007b, but it is rather basic and should work with any release that supports varargin and class().

引用格式

Nathaniel Brahms (2024). loadOptions (https://www.mathworks.com/matlabcentral/fileexchange/17882-loadoptions), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2007b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Argument Definitions 的更多信息
致谢

启发作品: parseParameters

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0