Search code examples
matlabuser-interfacecheckboxmatlab-uitable

Matlab Uitable Adding a logical column to existing table


I am using a UITABLE to display some data. After displaying the table i want to add a logical column to the end of the table. And depending on columns checked or unchecked future actions are taken. Any idea Guys?


Solution

  • An example:

    %# initial table
    c1 = rand(10,3);
    h = uitable('Units','normalized', 'Position',[0 0 1 1], 'Data',c1);
    
    %# add new column of check boxes
    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])
    

    screenshot

    You might want to handle the CellEditCallback to perform custom actions.