Storing values from editable gui table in a variable

11 vues (au cours des 30 derniers jours)
Bas van der Veen
Bas van der Veen le 29 Oct 2019
I'm trying to make an editable ui table that outputs a matrix of zero's and one's depending on which checkboxes in the table are checked. This matrix with the edited values should be stored in A, but I cannot figure out why this doesn't happen. This is my code:
function [A] = Gui()
fig = uifigure;
tdata = table('Size',[8 9],'VariableTypes',{'double','logical','logical','logical','logical','logical','logical','logical','logical'});
uit = uitable('Parent',fig,'Data',tdata,'ColumnEditable',true,'ColumnWidth',{2 2 2 2 2 2 2 2 2});
btn = uibutton(fig,'ButtonPushedFcn', @(btn,event) StoreTable(uit));
btn.Position = [80 80 100 22];
btn.Text = 'Store';
and:
function [A] = StoreTable(uit)
A = get(uit, 'Data');
disp(A);
Thanks in advance,
Bas

Réponse acceptée

Subhadeep Koley
Subhadeep Koley le 1 Nov 2019
Modifié(e) : Subhadeep Koley le 1 Nov 2019
I assume that you want to store the table in a variable in the workspace. You can achieve the same with the assignin() function. Refer the following code.
function GUI()
fig = uifigure;
tdata = table('Size',[8 9],'VariableTypes',{'double','logical','logical','logical','logical','logical','logical','logical','logical'});
uit = uitable('Parent',fig,'Data',tdata,'ColumnEditable',true,'ColumnWidth',{2 2 2 2 2 2 2 2 2});
uibutton(fig,'Position',[80 80 100 22],'Text','Store','ButtonPushedFcn', @(btn,event)StoreTable(uit));
end
function StoreTable(uit)
A = get(uit, 'Data');
disp(A);
A = table2array(A); % Comment out this line if you want data in Table format itself
assignin('base','A',A); % Assigning the table into the MATLAB base worksapce
end
  1 commentaire
Bas van der Veen
Bas van der Veen le 1 Nov 2019
Yes thank you, that was what I was looking for. I searched a lot on the web and on this forum but I never came across this assignin() command.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by