0
votes

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])
1
Not sure I'm getting the problem,... you can get the current table content at any time via get(h, 'Data'), just in the very same way as you're setting it in the above code. Is there a problem with that? - sebastian
I want to know the row numbers of a clicked checkboxes (column 4). - lroca
you need to set the CellSelectionCallback, it returns the indices of row and column. In the callback funtion you then get the complete data by get(yourUItablehandle, 'Data') and adress it with the indices you got before. - Robert Seifert
Thanks. Can you please explain me how can I use CellSelectionCallback. Is it possible to use it inside a Button_Callback as my main idea is to select rows that will be saved. Thanks again. - lroca
@thewaywewalk I guess that should rather be the CellEditCallback !? - sebastian

1 Answers

1
votes

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