Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 如何在Matlab中检查值是否为有效属性?_Class_User Interface_Matlab_Properties - Fatal编程技术网

Class 如何在Matlab中检查值是否为有效属性?

Class 如何在Matlab中检查值是否为有效属性?,class,user-interface,matlab,properties,Class,User Interface,Matlab,Properties,是否有一种方法可以检查属性值对于给定的对象是否有效? 我以下面的“enable”属性为例,我的问题是关于一般属性,假设您事先不知道所有可能接受的属性值 % MyBtnObject is a standard push button % this will be ok set(MyBtnObject, 'enable', 'on'); % and this will not, but how can I check it? set(MyBtnObject, 'enable', 'SomeInv

是否有一种方法可以检查属性值对于给定的对象是否有效? 我以下面的“enable”属性为例,我的问题是关于一般属性,假设您事先不知道所有可能接受的属性值

% MyBtnObject is a standard push button

% this will be ok
set(MyBtnObject, 'enable', 'on');

% and this will not, but how can I check it?
set(MyBtnObject, 'enable', 'SomeInventedProp');

我找到了答案。我可以使用
x=set(MyBtnObject,'enable')
获取enable属性的可能值,列为cell array
x

% find buttons
h = findobj('style', 'pushbutton');

% getting all the possible values for 'enable' property for all pushbuttons
% x = set(h, 'enable'), when h is array, will not work
x = arrayfun(@(x)(set(x, 'enable')), h, 'UniformOutput', false);

使用
try catch
块怎么样?