Using App Designer, saving (and loading) data from the Edit Fields of the GUI to a file?
33 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Rik
2023-4-23
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 JSON Format 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!