get uiTable data when using it in a function
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey,
I want to load a table in a uiTable, so the user can make changes. When closing this, I want to get the latest version of the table and save it in the workspace of the function, but it seems that the UI table is always made in the Base workspace?
I tried with th ecell editCalback but it can't find the 'uit' object,....
Then a second try was when closing the function:
function [table] = testTable()
table = readtable([[pwd,'\Configs\templates'],'\','vc_LYVP_template.csv']);
fig = uifigure;
uit = uitable(fig,'data',table);
uit.ColumnEditable = [false,true,false,false,false];
set(fig,'CloseRequestFcn',@myCloseFcn)
uiwait(fig)
end
function myCloseFcn(~,~)
table = get(uit,'data');
assignin('caller','table',table)
end
But I still get errors that ity can't find uit, or the data is saved in the base workspace in stead of the function
Does anyone have any idea on how to solve this?
0 commentaires
Réponse acceptée
Rik
le 19 Jan 2022
Modifié(e) : Rik
le 19 Jan 2022
If you want to stick with this setup you will have to make sure all variables exist in a share workspace. The easiest way would be to make your closing function a nested function, which would allow it to access variables in the parent function:
function [table] = testTable()
table = readtable([[pwd,'\Configs\templates'],'\','vc_LYVP_template.csv']);
fig = uifigure;
uit = uitable(fig,'data',table);
uit.ColumnEditable = [false,true,false,false,false];
set(fig,'CloseRequestFcn',@myCloseFcn)
uiwait(fig)
function myCloseFcn(hObject,~)
table = get(uit,'data');
delete(hObject) % something like gcbf will also work
end
end
I think this will work as intended.
Plus de réponses (0)
Voir également
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!