How can I extract data from UITABLE when the figure window is closed in MATLAB 7.6 (R2008a)?

2 views (last 30 days)
I have a simple UITABLE that I created using the UITABLE documentation. l would like to know how I can extract the data after the figure has closed, as the UITABLE handle is invalid as soon as the figure window is closed.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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)'); %note that gcbo is passed as argument
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.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!