2011-03-27 83 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);