0

In MATLAB, I've created a table with a callback function that is called before it deletes, to save all the information in a file:

t=uitable;
set(t,'Data',V1);
set(t,'ColumnEditable',c);
set(t,'DeleteFcn',@closeCallback);
waitfor(t); %wait until table closes

This is the callback function:

function closeCallback(src,eventdata)
%%
%this a callback function
h=gcbo();
A=table2array(h);
h=msgbox('Hi, I work!');
end

I intend on then saving the numeric array so I can use it in my normal program.

chappjc
  • 30,359
  • 6
  • 75
  • 132
user3273814
  • 198
  • 3
  • 16

1 Answers1

0

As @user3273814 points, the function table2array is not used for uitable. It is for table data type, which is no involved here.

The only thing that you need to do is to rewrite the closeCallback function in that way:

function closeCallback(src,eventdata, handles) %See changes here
  %%
  %this a callback function
  h=gcbo();
  %A=table2array(h);
  A = get(handles.t, 'Data') % See changes here
  h = msgbox('Hi, I work!');
end

please note that handles is a global object, which is automatically created by MATLAB when the event is triggered and it contains the references to all the graphics objects (the uitable named t in this case).

Using get I'm extracting the 'Data' property of the handles.t object created. If the content of the uitable is only numeric, you can use cell2mat in order to cast the returned data type to numeric.

Transfinito
  • 171
  • 3
  • 13