AppDesigner: save/load User‘s Input
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2019-7-16
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.
回答(1 个)
Kanishk
2025-1-4
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'))
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!