필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Harsha M V
Harsha M V 2018년 4월 27일
댓글: Harsha M V 2018년 5월 23일
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