0

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

脚本:

% 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])
4

1 回答 1

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
于 2013-12-11T12:52:43.203 回答