我正在matlab中的gui上工作。我有一个小问题无线电按钮和listlox。如何链接列表框和无线电按钮中的项目选择(检查还是取消)?有人能帮帮我吗?
如能提供任何帮助,请:)
发布于 2016-09-28 04:34:07
从您的描述中,我认为您有一个带有列表框和无线电按钮组的GUI,并且希望在列表框选择发生更改时更新所选选项。
您需要一个回调函数,它在每次列表框选择更改时执行。如果您使用指南( MATLAB创建工具)创建GUI,那么它很可能已经为您创建了这个函数。它看起来会像:
% --- Executes on selection change in myListBox.
function myListBox_Callback(hObject, eventdata, handles)
您希望在该函数中放入一些代码,以获取列表框(所选项)的当前状态,并相应地更新无线电按钮组选择。get和set命令在这里很有用。
contents = get(hObject,'String') % returns listbox contents as cell array
selection = contents{get(hObject,'Value')} % returns selected item from listbox
% <- code here to decide which radiobutton to select ->
set(handles.targetRadiobuttonHandle,'Value',1)
https://stackoverflow.com/questions/39742303
复制