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

Commit 1605623

Browse files
committed
Begin work on parameter pulling logic
1 parent fe8902c commit 1605623

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

saveGUIstate.m

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,78 @@
1-
function saveGUIstate(handles)
1+
function saveGUIstate(h)
2+
% Write better documentation here <-
3+
%
4+
% Input is a structure array of handles from programmatic or GUIDE GUIs
5+
% Output is a saved *.mat file with the specified properties
6+
%
7+
% Assumes all structure arrays with the same field name are of the same
8+
% object type (e.g. 3 sliders stored as h.slider(1), h.slider(2), ...) so
9+
% the user can utilize the return of set/get natively.
210

311
propertystruct = initializeproperties();
12+
outfilename = 'savedState.mat';
13+
14+
objectlist = fieldnames(h);
15+
16+
for ii = 1:length(objectlist)
17+
objtype = get(h.(objectlist{ii}), 'Type');
18+
if iscell(objtype)
19+
% Structure array length is non-singular, so get returns a cell
20+
% array where each cell corresponds to the property of an
21+
% individual object in the array.
22+
objtype = objtype{1};
23+
end
24+
fieldtest = isfield(propertystruct, objtype); % See if our field exists
25+
26+
% If we have a uicontrol object, adjust the object type string to
27+
% include the 'Style' property as well so the properties to output
28+
% structure can be addressed directly
29+
isuicontrol = strcmpi(objtype, 'uicontrol');
30+
if isuicontrol
31+
uicontrolstyle = get(h.(objectlist{ii}), 'Style');
32+
if iscell(uicontrolstyle)
33+
% Structure array length is non-singular, so get returns a cell
34+
% array where each cell corresponds to the property of an
35+
% individual object in the array.
36+
uicontrolstyle = uicontrolstyle{1};
37+
end
38+
39+
% isfield doesn't support nested fields, so we need to test the
40+
% uicontrol substructure directly
41+
fieldtest = isfield(propertystruct.uicontrol, uicontrolstyle);
42+
end
43+
44+
% Field exists, and there is data to save, save it
45+
if fieldtest
46+
% Need a in/else statement because you can't use dynamic field
47+
% references on nested structures
48+
if isuicontrol
49+
propstopull = propertystruct.uicontrol.(uicontrolstyle);
50+
else
51+
propstopull = propertystruct.(objtype);
52+
end
53+
54+
if ~isempty(propstopull)
55+
if iscell(propstopull)
56+
for jj = 1:length(propstopull)
57+
asdf = 1;
58+
end
59+
else
60+
asdf = 1;
61+
end
62+
end
63+
end
64+
end
465
end
566

667
function [propertystruct] = initializeproperties()
768
% Initialize structure containing the default properties to save.
869
% Fieldnames of propertystruct should match the 'Type' property of the UI
970
% object to save. If the object has multiple types (e.g. uicontrol), then
1071
% nest the types under their overall object type (e.g. uicontrol.edit).
72+
%
1173
% Strings (single or cell array) must match the property name(s).
1274

13-
propertystruct.figure = 'Position';
75+
propertystruct.figure = {'Units', 'Position'};
1476
propertystruct.axes = ''; % Nothing to save currently
1577
propertystruct.uipanel = ''; % Nothing to save currently
1678
propertystruct.uitabgroup = ''; % Nothing to save currently, introduced in R2014b

0 commit comments

Comments
 (0)