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.
  1 件のコメント
Ruben Dekeyser
Ruben Dekeyser 2022 年 1 月 20 日
Thanks! This works!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by