我做了一个 matlab gui,它有两个 uitables,其中一个在其单元格上有选择列表格式,但我不知道如何定义选择列表的每个案例并为每个案例放置 IF 函数。换句话说,我想将数字应用于另一个 gui 中的第二个 uitable,并依赖于第一个 uitable 选择列表中的案例。
我假设您使用guide
来管理 GUI,并且您已经创建了一个带有选择列表格式的列的uitable
,并且您已将ColumnEditable
属性设置为 true。是这样吗?
然后,通过右键单击指南窗口中的uitable
来创建CellEditCallback
函数,然后选择"查看回调"->"CellEditCallback"。如果到目前为止还不存在,这将创建回调函数。
自动创建的回调函数可能如下所示:
% --- Executes when entered data in editable cell(s) in uitable1.
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
在这种情况下,uitable
的标签是uitable1
.如果您的uitable
具有不同的标签,则函数名称将根据该标签。
现在,将if
块写入此回调函数。例如,如果要查询的选项列表位于uitable
的第一行和第一列中,并且要检查决策框的选定文本是否为"blabla",则代码将如下所示:
if strcmp(handles.uitable1.Data{1,1}, 'blabla')
% put here the code that you want to execute if the user selects 'blabla'
end
希望它有帮助...