Load data from .mat file in App Designer
69 ビュー (過去 30 日間)
古いコメントを表示
I am loading data from a .mat file in App Designer. The user selects the .mat file and I would like to load a variable from the selected file, assigning it to an existing property in the app, like this:
app.x = load([app.path '\' app.file],'inputVariable');
I want to assign inputVariable, a timetable, to app.x, which is used as a timetable elsewhere in the app. But with the load command, app.x becomes a struct with a field named inputVariable that is a timetable. So, app.x.inputVariable is the timetable I end up with. I could create an intermediate variable internal to the function where this is happening and then apply it to the property, like this:
tempX = load([app.path '\' app.file],'inputVariable');
app.x = tempX.inputVariable;
clear tempX;
Or I could load the inputVariable without assigning it so the variable loaded is a timetable rather than a struct with a field that is a timetable:
load([app.path '\' app.file],'inputVariable');
app.x = inputVariable;
clear inputVariable;
This works but it just seemed inefficient. Is there a better way to do this? Thanks.
0 件のコメント
採用された回答
Ameer Hamza
2020 年 4 月 22 日
編集済み: Ameer Hamza
2020 年 4 月 22 日
Loading into a temporary variable and then assigning it to app.X is the correct method in MATLAB (I guess you made a mistake while writing your second method, check the following lines of code). Don't worry about it being inefficient. MATLAB will not create two copies of the table when you assign it to the field in the app. MATLAB use copy-on-write so only one copy is made of the table in memory: https://www.mathworks.com/help/matlab/matlab_prog/avoid-unnecessary-copies-of-data.html
tempX = load([app.path '\' app.file],'inputVariable');
app.x = tempX.inputVariable;
その他の回答 (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!