get uiTable data when using it in a function

5 次查看(过去 30 天)
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?

采纳的回答

Rik
Rik 2022-1-19
编辑:Rik 2022-1-19
For general advice and examples for how to create a GUI, have look at this thread.
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by