gpt4 book ai didi

class - 如何检查值是否是 Matlab 中的有效属性?

转载 作者:行者123 更新时间:2023-12-02 02:27:13 24 4
gpt4 key购买 nike

有没有办法检查属性值对给定的对象是否有效?我以下面的“启用”属性为例,我的问题是针对一般属性,并假设您事先不知道所有可能接受的属性值。

% 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

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

关于class - 如何检查值是否是 Matlab 中的有效属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5448161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com