matlab - 如何在 uitable (GUI) 中定义选择列表的每个案例并为每个案例添加 IF 函数?
问题描述
我制作了一个有两个 uitables 的 matlab gui,其中一个在其单元格上有选择列表格式,但我不知道如何定义选择列表的每个案例并为每个案例添加 IF 函数。换句话说,我想将数字应用到另一个 gui 中的第二个 uitable,并依赖于第一个 uitable 的选择列表中的案例。
解决方案
我假设您使用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)
在这种情况下, 的标签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
希望能帮助到你 ...
推荐阅读
- git - Git - 行特定哈希\标签
- tensorflow - TensorFlow 模型到 TFLITE
- java - 创建一个与一个对象相关联但具有不同特征的对象
- c++ - 可以使用 std 容器为函数模板推导出类型参数吗?
- php - 在laravel中计算从当前日期和出生日期派生的年龄
- python - 从字符串中查找每个关键字的分数
- c# - ASP.NET Core 3.1:Web API 身份登录
- javascript - Jquery 自定义数据表导出选项
- python - 如何使用python计算没有空格的字符串中的字符?
- postgresql - 在 plpgsql/postgresql 中引发错误而不回滚