AsiJapan
AsiJapan

Reputation: 313

Autofill a Cell in a uitable - Matlab

I have a comment field in a uitable that I wish to autofill based on other comments entered previously in the same column. Is it possible to program it in Matlab without using Java?

Upvotes: 1

Views: 124

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112749

You can use the 'CellEditCallback' of the uitable. The code you write there (such as a function call) is executed whenever the value of a cell is edited.

Here's an example, which updates the last column with the sum of the other two.

t = uitable('Data', [10 30 40], 'ColumnName', {'Column 1', 'Column 2', 'Sum'}, ...
    'ColumnEditable', [true true false], 'Position', [20 20 260 100]);
set(t, 'CellEditCallback', ...
    'd = get(gcbo, ''Data''); set(gcbo, ''Data'', [d(1:end-1) sum(d(1:end-1))])')

enter image description here

Upvotes: 1

Related Questions