2011-03-27 46 views
3

有没有一种方法来检查给定的hobject的属性值是否有效? 我只是把'enable'属性作为一个例子,我的问题是针对一般属性,并且假设您事先并不知道所有可能接受的属性值。如何在Matlab中检查值是否有效属性?

% 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'); 
+0

如何使用'try-catch'块? – 2011-03-27 15:12:52

回答

2

我找到了答案。我可以使用x = set(MyBtnObject, 'enable')来获取启用属性的可能值,列为单元阵列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);