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
0 件のコメント
採用された回答
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
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 Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!