Save and load all GUIDE GUI variables
显示 更早的评论
Guys -
I built a GUI in GUIDE that's basically a bunch of text edit windows and pushbuttons to call different operations. I'd like to be able to save all the values entered in my text edit windows for later recall when I start a new session with my GUI. Is there a way I can do this by saving all the handles as a single variable as in [guidata(hObject, handles)] and then loading that single variable to populate the text edit windows with those values?
采纳的回答
更多回答(3 个)
Sean de Wolski
2012-1-16
0 个投票
Check out this video:
Walter Roberson
2012-1-16
No; the values that are stored for handles are double precision values that provide an internal reference to the real data. If you store those double precision values and load them back in a different session, the real data will not exist to be referred to.
Instead, you can use something like this:
Isgraphic = structfun(@(F) isnumeric(F) && length(F) == 1 && ishandle(F), handles);
fnames = fieldnames(handles);
fvals = struct2cell(handles);
structparts = [fnames(Isgraphic).', get([fvals{IsGraphic}],'String').'];
saved_edit_fields = struct(structparts{:});
and save saved_edit_fields
Then when you load:
fnames = fieldnames(saved_edit_fields);
fvals = struct2cell(saved_edit_fields);
Isgraphic = cellfun(@(F) isfield(handles.(F)) && ishandle(handles.(F)), fnames);
for K = find(Isgraphic)
set(handles.(fnames{K}), 'String', fvals{K});
end
Or reasonable hand-drawn facsimile thereof.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!