Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Billie Jean
Billie Jean le 11 Nov 2016
Commenté : Walter Roberson le 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 commentaires
Walter Roberson
Walter Roberson le 11 Nov 2016
Please show the bit about creating the second table and the bit about displaying it.
Billie Jean
Billie Jean le 11 Nov 2016
Modifié(e) : Walter Roberson le 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.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 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 commentaires
Billie Jean
Billie Jean le 11 Nov 2016
Modifié(e) : Billie Jean le 11 Nov 2016
How can I employ linkprop here?
Walter Roberson
Walter Roberson le 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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by