将标志传递给Matlab函数的最巧妙的方法是什么? [英] What is the neatest way of passing flags to a Matlab function?
本文介绍了将标志传递给Matlab函数的最巧妙的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在设计一个函数,该函数将一个结构和任意数量的标志作为参数.该函数将包含几个if
检查是否设置了特定标志的.
I'm designing a function that takes as argument one structure and any number of flags. The function will contain a couple of if
s checking whether a specific flag is set.
最简单的方法是什么?我正在考虑将标志作为单独的字符串参数传递.有更整洁的解决方案吗?
What is the neatest way to achieve this? I was thinking about passing the flags as separate string arguments. Is there a neater solution?
推荐答案
我会像使用varargin
和ismember
那样:
function foo(arg1,arg2,varargin)
flag1=ismember('flag1',varargin);
flag2=ismember('flag2',varargin);
flag3=ismember('flag3',varargin);
您可以这样调用该函数:
And you can call the function like that:
foo(a1,a2,'flag3','flag1')
这将激活flag1
和flag3
.
这篇关于将标志传递给Matlab函数的最巧妙的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文