Using App Designer, saving (and loading) data from the Edit Fields of the GUI to a file?

33 visualizaciones (últimos 30 días)
I have several numeric edit fields in my gui. How do I go about saving the entered data to a text file?
I want to be able to save the entered values for the above Center Freq and Bandwidths to a file so I can recall them at a later time. Those fields are app.NumericEditField_CenterFreq1, app.NumericEditField_Bandwidth1, app.NumericEditField_CenterFreq2, etc.
I have save and load buttons, and understand I need to place code in the call backs of those buttons, but I haven't been able to find any good examples. I tried the below, but it saves it to a .mat file, which is unreadable in a text error. Is there an easier way to save and then load the data to and from my edit fields?
function SaveButtonPushed(app, event)
props = properties(app);
lp = length(props);
values = cell(1,lp);
visibilities = cell(1,lp);
for i = 1:lp
propName = props{1};
property = app.(propName);
if isprop(property, 'Value')
values{i} = app.(propName).Value;
end
end
file = uiputfile('*.mat', "Save Message" );
if file
save(file, 'props', 'values', 'visibilities');
end
The above saves data, but not sure if it is correct since it is unreadable. When I try and load, I dont get anything in the edit fields:
function LoadButtonPushed(app, event)
[file,path] = uigetfile('*.mat');
selectedfile = fullfile(file);
data=load(selectedfile);
end
Thanks in advance!

Respuesta aceptada

Rik
Rik el 23 de Abr. de 2023
Your loading function needs to load the file, and then set the values of the fields. It currently only does the former.
A mat file is not a text file. You can examine the contents with Matlab (or even Octave), but not with text readers. If you want a text file, you may consider converting to JSON.
  15 comentarios

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by