get uiTable data when using it in a function

조회 수: 5 (최근 30일)
Ruben Dekeyser
Ruben Dekeyser 2022년 1월 19일
댓글: Ruben Dekeyser 2022년 1월 20일
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