Saving the application (Appdesigner) together with provided inputs

11 views (last 30 days)
Hello everyone,
I have generated a program composed of 7 Tabs. In each tab, the user provides some inputs. Using the provided inputs, the program provides some results.
For example, in the "Girder Properties" Tab, the user provides the beam type, then checks the necessary analysis types. After that, by using the button "Lock the selections made above", a dropdown menu comes out. After selecting one option in that list, a table appears. In that table, the user provides some inputs as shown in yellow frame.
I want to provide a button in the program such that it saves the program together with selected options and provided inputs. By this way, the user can follow where he or she left. (Like "Save as" option in many professional commecially available programs: Matlab, Mathcad, Abaqus etc.). I have searched one the options in this platform but, it did not work. Can anybody have a suggestion?
Regards

Accepted Answer

Adam Danz
Adam Danz on 31 Oct 2020
"I want to provide a button in the program such that it saves the program together with selected options and provided inputs."
Unfortunately a save-as function for apps/guis does not exist but you could create a custom save-as function for your app. Within the save-as callback function you can save app component properties to a mat file but don't copy handles. Those values can be loaded back into the app using the reverse process.
For example,
function SaveasButtonPushed(app, event)
C = {...
app.ListBox.Value;
app.ListBox.Items;
app.CheckBox.Value;
app.TextArea.Value;
app.TextArea.ValueChangedFcn;
app.UIAxes.XData;
app.UIAxes.YData;
};
save('appData.mat','C') % use full path & better variable and file names!
end
function LoadAppStateButton(app, event)
C = load('appdata.mat', 'C');
C = C.C;
% Same order as SaveasButtonPushed
app.ListBox.Value = C{1};
app.ListBox.Items = C{2};
app.CheckBox.Value = C{3};
app.TextArea.Value = C{4};
app.TextArea.ValueChangedFcn = C{5};
app.UIAxes.XData = C{6};
app.UIAxes.YData = C{7};
end
Problems with this approach
  • Lots of manual work - especially if you need to save plot objects. In that case, consider exporting the entire plot using exportgraphics or copyUIAxes and then loading those graphics back in using copyobj().
  • The programmer must remember to make the same changes in both functions and the order of saved items is important.
  3 Comments
Adam Danz
Adam Danz on 1 Nov 2020
I completely understand and have experienced the same burden. As of r2020b you can take snapshot images of apps (see here) which helps to record the state of an app but it doesn't help when you want to reload the app state.
Saving the UIFigure of an app is also not a possibility.
Saving the entire handle to graphics objects leads to problems when loading those handles after the original graphics objects have been deleted.
So that's the only way I can think of to save the app's state.
Perhaps another solution would be to record the user's actions by logging all changes in a log file. For example, every time a user changes the value of a knob, dropdown menu, etc, the callback function records the action as a line of text in a log file. That's just as cumbersome as the other idea, if not more so.
I'd be very happy to hear about alternatives. You can also write to Mathworks Tech Support to request this feature for future releases.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!