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

1 Ansicht (letzte 30 Tage)
Billie Jean
Billie Jean am 11 Nov. 2016
Kommentiert: Walter Roberson am 12 Nov. 2016
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 Kommentare
Walter Roberson
Walter Roberson am 11 Nov. 2016
Please show the bit about creating the second table and the bit about displaying it.
Billie Jean
Billie Jean am 11 Nov. 2016
Bearbeitet: Walter Roberson am 11 Nov. 2016
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 11 Nov. 2016
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 Kommentare
Billie Jean
Billie Jean am 11 Nov. 2016
Bearbeitet: Billie Jean am 11 Nov. 2016
How can I employ linkprop here?
Walter Roberson
Walter Roberson am 12 Nov. 2016
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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by