Matlab:检查uitable中的单元格状态

时间:2013-12-11 10:38:38

标签: matlab matlab-uitable

我希望创建一个if语句,用于检查uitable中逻辑列的特定单元格是true还是false。因此,如何检查逻辑单元状态(单击按钮后,未显示)?

脚本:

% Table
c1 = rand(10,3);
h = uitable('Units','normalized', 'Position',[0 0 1 1], 'Data',c1);

%# add new column of check boxes to table
c2 = c1(:,1)>0.5;
set(h, 'Data',[num2cell(c1) num2cell(c2)], 'ColumnFormat',[repmat({[]},1,size(c1,2)),'logical'], 'ColumnEditable',[false(1,size(c1,2)),true])

1 个答案:

答案 0 :(得分:1)

如果要在按钮回调中获取所选行,则不需要CellSelection / CellEditCallback。

正如我在第一条评论中所建议的那样,只需获取数据并找到所选行:

function button_callback(hObject, evt, handles)

    % get the data - identical to setting the data
    data = get(handles.tableHandle, 'Data');
    checkBoxColumn = 4;

    % logical indices of selected rows
    isRowSelected = [data{:, checkBoxColumn}];

    % if you want the indices
    idxSelectedRows = find(isRowSelected);
end