首页 > 解决方案 > 如何在 uitable (GUI) 中定义选择列表的每个案例并为每个案例添加 IF 函数?

问题描述

我制作了一个有两个 uitables 的 matlab gui,其中一个在其单元格上有选择列表格式,但我不知道如何定义选择列表的每个案例并为每个案例添加 IF 函数。换句话说,我想将数字应用到另一个 gui 中的第二个 uitable,并依赖于第一个 uitable 的选择列表中的案例。

标签: matlablistuitableviewchoice

解决方案


我假设您使用guide来管理您的 GUI,并且您已经创建了uitable一个选项列表格式的列,并且您已将ColumnEditable属性设置为 true。是这样吗?

然后,CellEditCallback通过右键单击uitable指南窗口中的 并选择“查看回调”->“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)

在这种情况下, 的标签uitableuitable1。如果您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

希望能帮助到你 ...


推荐阅读