本文介绍了如何检查值是否是有效的属性在Matlab中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来检查属性值是否对给定的hobject有效?
我把下面的'enable'属性作为一个例子,我的问题是一般属性,并假设你不知道所有可能接受的属性值。

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


推荐答案

我可以使用 x = set(MyBtnObject,'enable')获取enable属性的可能值,列为单元格数组 x

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

这篇关于如何检查值是否是有效的属性在Matlab中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 15:46