How to check if a value is a valid property in Matlab?

Is there a way to check if a property value is valid for a given object? I took the "enable" property below, as an example, my question relates to a general property and assumes that you do not know in advance all the possible valid values ​​of the properties.

% 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'); 
+3
source share
1 answer

I have found the answer. I can use x = set(MyBtnObject, 'enable') to get the possible values ​​of the enable property, listed as an array of x cells.

 % 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); 
+2
source

Source: https://habr.com/ru/post/950009/


All Articles