To extract the data from the UITABLE fields as soon as the figure window is closed, you can use the 'DeleteFcn' property of UITABLE. By using this property, you can specify a callback routine that executes when you delete the uitable object (e.g., when you issue a DELETE command or clear the figure containing the uitable or when you close the figure). Please note that the handle of the object whose DeleteFcn is being executed is accessible only through the root CallbackObject property, which you can query using GCBO.
The following code sample create a simple UITABLE object and calls a function 'MyDeleteFcn' when the UITABLE object is destroyed.
f = figure('Position',[100 100 400 150]);
dat = {6.125, 456.3457, true, 'Fixed';...
6.75, 510.2342, false, 'Adjustable';...
7, 658.2, false, 'Fixed';};
columnname = {'Rate', 'Amount', 'Available', 'Fixed/Adj'};
columnformat = {'numeric', 'bank', [], {'Fixed' 'Adjustable'}};
columneditable = [false false true true];
t = uitable('Units','normalized','Position',...
[0.1 0.1 0.9 0.9], 'Data', dat,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'DeleteFcn','data = MyDeleteFcn(gcbo)');
The function definition for MyDeleteFcn is as below:
function data = MyDeleteFcn(t)
data = get(t,'Data');
Now when the user makes changes to UITABLE object and closes it, MyDeletFcn is called and the table data is stored into the variable 'data'.
To read more about DeleteFcn and other properties of the UITABLE object, please refer to the UITABLE properties documentation page.
Best Answer