Skip to content
This repository was archived by the owner on Nov 25, 2018. It is now read-only.

Commit a036de4

Browse files
committed
Initial loading fuctionality
1 parent 8d3f917 commit a036de4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

loadGUIstate.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function loadGUIstate(GUIstate, h)
2+
% Write better documentation here <-
3+
%
4+
% Input is a structure containing the saved GUI state output by
5+
% saveGUIstate along with the handles structure of the target GUI.
6+
% This function modifies the GUI handles directly so there is no output
7+
%
8+
% Assumes the GUI state is being loaded into the same GUI that it was saved
9+
% from
10+
11+
savedobjlist = fieldnames(GUIstate);
12+
13+
for ii = 1:length(savedobjlist)
14+
% Verify that our saved handle is part of the passed handles structure,
15+
% otherwise ignore it
16+
if isfield(h, savedobjlist{ii}) && ~isempty(GUIstate.(savedobjlist{ii}))
17+
% set can address properties of multiple objects at the same time,
18+
% which is useful for nested structure arrays of handles (e.g. 3
19+
% sliders stored as h.slider(1), h.slider(2), ...)
20+
nsubhandles = length(h.(savedobjlist{ii}));
21+
22+
% set can also set multiple properties at once, where each row of
23+
% the passed cell array is the value to pass for each object
24+
% handle. This syntax will not be utilized until a robust method
25+
% for generating the cell array is developed. Get something
26+
% functional first, then prettify...
27+
propstoset = fieldnames(GUIstate.(savedobjlist{ii}));
28+
for jj = 1:length(propstoset)
29+
if nsubhandles == 1
30+
ValueArray = {GUIstate.(savedobjlist{ii}).(propstoset{jj})};
31+
elseif nsubhandles > 1
32+
ValueArray = GUIstate.(savedobjlist{ii}).(propstoset{jj});
33+
end
34+
set(h.(savedobjlist{ii}), propstoset(jj), ValueArray);
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)