In GUI, how to obtain table data after editing its content ?

1 次查看(过去 30 天)
I'm generating table after pressing push_button:
function pushbutton1_Callback(hObject, eventdata, handles)
a = 3;
b = str2num(get(handles.edit2,'String'));
data = cell(1,b);
data(:) = {''};
h1 = uitable('Parent', handles.uipanel1, 'FontSize', 10, 'Position', [10 100 400 60], 'RowName',{'Gene'}, 'ColumnWidth', {60}, 'ColumnEditable', true, 'Data', data)
Now, after changing the cell data in GUI, by pressing another push_button, how do I get the new updated table data ?
Thanking You,
Harsha

采纳的回答

Walter Roberson
Walter Roberson 2018-4-27
You need to find the uitable somehow, and then get() its Data property.
There are multiple ways of doing that. One would be to write to handles.h1 instead of h1, and then to do
guidata(hObject, handles);
so that the handle of the table got written into the handles data structure.
Another way would be to give the uitable a Tag property, and later findobj() based on the Tag.
  3 个评论
Walter Roberson
Walter Roberson 2018-4-27
h1 = uitable('Parent', handles.uipanel1, 'FontSize', 10, 'Position', [10 100 400 60], 'RowName',{'Gene'}, 'ColumnWidth', {60}, 'ColumnEditable', true, 'Data', data, 'Tag', 'panel1');
Later:
h1 = findobj(0, 'tag', 'panel1')
"How to write to handles.h1, when table is not created in GUIDE. "
Your code
function pushbutton1_Callback(hObject, eventdata, handles)
implies that you either used GUIDE to create the overall GUI, or else that you wrote all of the GUI yourself but decided to use the same idea of the handles structure. In either of those cases, you would do
handles.h1 = uitable('Parent', handles.uipanel1, 'FontSize', 10, 'Position', [10 100 400 60], 'RowName',{'Gene'}, 'ColumnWidth', {60}, 'ColumnEditable', true, 'Data', data);
guidata(hObject, handles);
Once you had done that, in any later callbacks that pass in handles, you would use
handles.h1
to get to the handle.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by