当前位置: 动力学知识库 > 问答 > 编程问答 >

class - How to check if value is valid property in Matlab?

问题描述:

Is there a way of checking whether a property value is valid for the given hobject?

I took the 'enable' property below just as an example, my question is for general property, and assuming you don't know all the possible accepted properties values in advance.

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

网友答案:

I've found the answer. I can use x = set(MyBtnObject, 'enable') to get the possible values to the enable property, listed as 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);
分享给朋友:
您可能感兴趣的文章:
随机阅读: