필터 지우기
필터 지우기

How to allow user to modify data in a table in GUI?

조회 수: 3 (최근 30일)
Billie Jean
Billie Jean 2016년 11월 11일
댓글: Walter Roberson 2016년 11월 12일
I have a table and two pushbuttons in GUI. When I click the first button it displays the table. And when I press the second one it displays another table which was created by using the data in the fisrt table. I can allow user to modify the data in the fisrt table. However when I try to display the second table it displays the same result before the modifications were made.
Example:
t1: var1 var2 var3
0 1 3
1 3 2
t2: var1
2
3
I modify the table as:
t1: var1 var2 var3
2 1 1
3 0 1
but the table2 remans the same:
t2: var1
2
3
I have the following piece of code:
handles.data=[handles.C{1} handles.nums];
handles.f = figure;
handles.t = uitable(handles.f,'ColumnEditable', [true,true,true,true]);
handles.t.Data=handles.data;
  댓글 수: 4
Walter Roberson
Walter Roberson 2016년 11월 11일
Please show the bit about creating the second table and the bit about displaying it.
Billie Jean
Billie Jean 2016년 11월 11일
편집: Walter Roberson 2016년 11월 11일
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
handles.fileName = uigetfile;
handles.fid=fopen(handles.fileName);
handles.C=textscan(handles.fid, '%s %f %f %f');
handles.nums=num2cell([handles.C{2}, handles.C{3}, handles.C{4}]);
handles.data=[handles.C{1} handles.nums];
handles.f = figure;
handles.t = uitable(handles.f,'ColumnEditable', [true,true,true,true],'Data',handles.data);
handles.cellArray = get(handles.t, 'Data');
guidata(hObject,handles);
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
handles.nodeVoltages=circuit(handles.cellArray);
handles.ff=figure;
handles.t = uitable(handles.ff);
handles.t.Data=handles.nodeVoltages;
circuit is a function that I wrote. It takes a cell array and gives an array as output.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 11일
That result is expected. Modifying one uitable never affects another uitable, not unless the two have had their contents linked together using linkprop(), or not unless there are callbacks set on the first table that tell it to update the second table as well.
  댓글 수: 2
Billie Jean
Billie Jean 2016년 11월 11일
편집: Billie Jean 2016년 11월 11일
How can I employ linkprop here?
Walter Roberson
Walter Roberson 2016년 11월 12일
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
handles.fileName = uigetfile;
fid = fopen(handles.fileName);
C = textscan(fid, '%s %f %f %f');
nums = num2cell([C{2}, C{3}, C{4}]);
data = [handles.C{1} handles.nums];
handles.f = figure;
handles.t = uitable('Parent', handles.f, 'ColumnEditable', [true,true,true,true], 'Data', data);
guidata(hObject, handles);
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
cellArray = get(handles.t, 'Data');
nodeVoltages = circuit(handles.cellArray);
handles.ff = figure;
handles.t2 = uitable('Parent', handles.ff, 'Data', nodeVoltages );
guidata(hObject, handles);

댓글을 달려면 로그인하십시오.

카테고리

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