Class 如何在Matlab中检查值是否为有效属性?
是否有一种方法可以检查属性值对于给定的对象是否有效? 我以下面的“enable”属性为例,我的问题是关于一般属性,假设您事先不知道所有可能接受的属性值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
% 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 arrayx
% 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
块怎么样?