AppDesigner: save/load User‘s Input

11 visualizzazioni (ultimi 30 giorni)
Jule Zimmermann
Jule Zimmermann il 16 Lug 2019
Risposto: Kanishk il 4 Gen 2025
Hey everyone,
I built a gui with appdesigner, where the user has to fill out many editfields, drop down lists and switches. At the end he can push a plot button, which runs some calculations and shows the plot after all. So far so good, I want to built in two buttons ‚save‘ and ‚load‘, so the user can save all the input information and load it again another time, to run the same scenario without allthe input effort. Any suggestions how to program this? Best regards, Jule
  1 Commento
Adam
Adam il 16 Lug 2019
Just grab all the inputs from the UI via the class object, put them in a struct and save it to a mat file. Then do the reverse when you load it back in.

Accedi per commentare.

Risposte (1)

Kanishk
Kanishk il 4 Gen 2025
To implement save and load functionality in your MATLAB App Designer GUI, you can use MATLAB's file I/O functions to store and retrieve the user input data.
To save the data, gather all the values from the fields. Use the "uiputfile" function to prompt the location and filename, and save the data using "save".
To load data, use the "uigetfile" function to select a file, and load the data using "load". Set the values of the fields from the loaded data.
Here is a simple example of the callback function for Save and Load buttons.
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
inputData.editField1 = app.EditField1.Value;
inputData.editField2 = app.EditField2.Value;
inputData.dropDown = app.DropDown.Value;
inputData.switch = app.Switch.Value;
% Prompt user to save file
[file, path] = uiputfile('*.mat', 'Save Input Data');
if isequal(file, 0)
return; % User canceled
end
save(fullfile(path, file), 'inputData');
end
% Button pushed function: LoadButton
function LoadButtonPushed(app, event)
[file, path] = uigetfile('*.mat', 'Load Input Data');
if isequal(file, 0)
return; % User canceled
end
% Load data
loadedData = load(fullfile(path, file));
% Populate UI components with loaded data
app.EditField1.Value = loadedData.inputData.editField1;
app.EditField2.Value = loadedData.inputData.editField2;
app.DropDown.Value = loadedData.inputData.dropDown;
app.Switch.Value = loadedData.inputData.switch;
end
To learn more about 'uiputfile', 'uigetfile', 'save' and 'load' you can use the following commands to access the documentation.
web(fullfile(docroot, 'matlab/ref/uiputfile.html'))
web(fullfile(docroot, 'matlab/ref/uigetfile.html'))
web(fullfile(docroot, 'matlab/ref/save.html'))
web(fullfile(docroot, 'matlab/ref/load.html'))

Categorie

Scopri di più su App Building in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by