【问题标题】:Matlab, Hide edittext and static text with radiobutton in GUIMatlab,在 GUI 中使用单选按钮隐藏编辑文本和静态文本
【发布时间】:2015-01-09 14:33:46
【问题描述】:

这是我的列表,用于隐藏静态文本并在 gui 中编辑文本,但它不起作用

function uipanel1_CreateFcn(hObject, eventdata, handles)   
    switch get(eventdata.NewValue,'Tag')
        case radiobutton1
            set(handles.text5, 'Visible', 'On');
            set(handles.edit4, 'Visible', 'On');
        case radiobutton2
            set(handles.text5, 'Visible', 'Off');
            set(handles.edit4, 'Visible', 'Off');
        case radiobutton3
            set(handles.text5, 'Visible', 'Off');
            set(handles.edit4, 'Visible', 'Off');
    end

告诉我我的listing有什么错误

【问题讨论】:

  • 如果您忘记在 switch 语句中使用字符串,请检查 here。 IE。 case 'radiobutton1'

标签: matlab radio-button matlab-guide


【解决方案1】:
radiobutton(tag)=get(hObject,'Value');
if radiobutton(tag)
    set(handles.edittext,'Enable','off')
    set(handles.statictext,'Enable','off')
else
    set(handles.edittext,'Enable','on')
    set(handles.statictext,'Enable','on')
end
guidata(hObject,handles);

【讨论】:

  • 感谢您抽出宝贵时间提供答案!请解释您的修改以及为什么您的解决方案应该在原始版本失败的情况下工作 - 这样您的帖子将有更高的机会在未来对其他人有用。
  • 关于修改只需将您要给它的名称添加到单选按钮的标签中,将此代码放在单选按钮的回调中,如果您想释放该空间,请输入以下代码: set(handles.editTDma ,'细绳','');在第一个 IF 中,我希望它回答了你的问题 :)
  • 欢迎来到 Stack Overflow!虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
猜你喜欢
  • 1970-01-01
  • 2020-05-05
  • 2013-09-01
  • 2010-10-13
  • 1970-01-01
  • 2011-02-24
  • 1970-01-01
  • 2017-04-22
  • 1970-01-01
相关资源
最近更新 更多