上海网站建设改版,网站建设与维护方案,台州做网站那家好,软件下载网站推荐免费的我喜欢使用结构为我的选择。这给你一个简单的方法来存储选项和一个简单的方法来定义它们。此外#xff0c;整个事情变得相当紧凑。function example(varargin)%# define defaults at the beginning of the code so that you do not need to%# scroll way down in case you wan…我喜欢使用结构为我的选择。这给你一个简单的方法来存储选项和一个简单的方法来定义它们。此外整个事情变得相当紧凑。function example(varargin)%# define defaults at the beginning of the code so that you do not need to%# scroll way down in case you want to change something or if the help is%# incompleteoptions struct(firstparameter,1,secondparameter,magic(3));%# read the acceptable namesoptionNames fieldnames(options);%# count argumentsnArgs length(varargin);if round(nArgs/2)~nArgs/2error(EXAMPLE needs propertyName/propertyValue pairs)endfor pair reshape(varargin,2,[]) %# pair is {propName;propValue}inpName lower(pair{1}); %# make case insensitiveif any(strcmp(inpName,optionNames))%# overwrite options. If you want you can test for the right class here%# Also, if you find out that there is an option you keep getting wrong,%# you can use if strcmp(inpName,problemOption),testMore,end-statementsoptions.(inpName) pair{2};elseerror(%s is not a recognized parameter name,inpName)endend