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!