Saving Entries to Editable UI Table as a Variable in the Workspace
3 次查看(过去 30 天)
显示 更早的评论
I am currently working in App Designer to create a GUI. And am having trouble with saving entries of an editable UI Table as a variable in the workspace. My hope is that by saving this data, I will be able to call it in another tab within the same GUI.
The first through third photos show the coded functionalities so far. The fourth picture shows entries I would like to save. So far I have tried saving them using:
% Button pushed function: LvlgSaveFileButton
app.LvlgData = app.UITableLvlg.Value
and
% Button pushed function: LvlgSaveFileButton
function LvlgSaveFileButtonPushed(app, event)
app.LvlgData = get(app.UITableLvlg);
app.LvlgData = table2array(table(app.LvlgData));
and
% Button pushed function: LvlgSaveFileButton
function LvlgSaveFileButtonPushed(app, event)
assignin('base', app.LvlgData, app.UITableLvlg)
end
and
% Button pushed function: LvlgSaveFileButton
function LvlgSaveFileButtonPushed(app, event)
app.LvlgData = cellstr(struct2cell(get(app.UITableLvlg)))
I have also tried to follow the solution to a similar problem: https://www.mathworks.com/matlabcentral/answers/179029-how-to-save-data-of-uitable-in-workspace. But have been largely unsuccessful. Any help would be appreciated.
2 个评论
Stephen23
2021-2-10
"My hope is that by saving this data, I will be able to call it in another tab within the same GUI. "
Rather than very messing about with other workspaces, the simple and efficient way to pass data around an App Designer GUI is to store it as an object property. Is there a particular reason why that does not work for you?
https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
The documentation states "Using properties is the best way to share data within an app because properties are accessible to all functions and callbacks in an app". In contrast your approach is inefficient, indirect, liable to bugs, difficult to debug, and obfuscates the intent.
回答(1 个)
Mario Malic
2021-2-10
Hello,
This line makes you an error, UITableLvlg is a table and it doesn't have Value property.
app.LvlgData = app.UITableLvlg.Value;
Secondly, whiile properties of the app are convenient for sharing the data between the callbacks, if what you're doing is simple enough, you can obtain data from the components directly rather than saving them in another property and reusing it.
I'd highly suggest you to do few introductory examples in App Designer, it's going to help a lot.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!