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!