Search code examples
matlabmatlab-uitable

Matlab: check cell status inside uitable


I wish to create an if statement that will check if a specific cells of a logical column inside a uitable are true or false. Therefore, how can I check the logical cell status (upon clicking a push button, not shown)?

Script:

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

Solution

  • If you want to get the selected rows in a button-callback, there's no need for the CellSelection/CellEditCallback.

    As I suggested in my first comment, simply get the data and find the selected rows:

    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