设置命令有两种设置属性值的可能性
对于 matlab 中的某些 hobject,set(hobject, 'enable', 'inactive')
命令可以正常工作。
对于其他的,比如工具栏按钮,只有set(hobject, 'enable', 'off')
。
我是否有一组 listObjects
,
是否有类似 set(listObjects, 'enable', ['inactive'|'off'])
的内容,其中我如果属性有效,则将其设置为“非活动”;如果属性无效,则将其设置为“关闭”?
For some hobjects in matlab, the set(hobject, 'enable', 'inactive')
command will work fine.
for others, like toolbar buttons, there's only set(hobject, 'enable', 'off')
.
Is I have a set of listObjects
,
is there something like set(listObjects, 'enable', ['inactive'|'off'])
in which I set the property to 'inactive' if it's valid, and 'off' if it's not a valid property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只需要检查两个值,则可以使用
try/catch
块。这样,它会在您第一次尝试设置该值时检查该值是否可接受。如果没有,它会尝试下一个替代方案。如果错误是由于其他原因造成的(例如,您输入了无效的属性名称),则会将错误抛出到屏幕上。
顺便说一句,当我尝试设置属性不接受的值时,我在计算机上遇到了错误标识符:
MATLAB:hg:propswch:FindObjFailed
。尽管我怀疑它应该是相同的,但您可能想看看您在计算机上得到了什么并在strcmp
函数中使用它。If you have only two values that you need to check, you can use a
try/catch
block.This way it checks the first time you try to set the value, if it is acceptable. If not, it tries the next alternative. If the error is due to something else (for e.g., you entered an invalid property name), it throws the error to the screen.
BTW, the error identifier:
MATLAB:hg:propswch:FindObjFailed
was what I got on my machine when I tried to set a value that the property wouldn't accept. Although I suspect it should be the same, you might want to see what you get on your machine and use that in thestrcmp
function.您可以首先通过读取对象的
'enable'
属性来检查对象的“类型”。You can check for the 'type' of objects by reading their
'enable'
property first.