I'm implementing a GUI-based simulation program comprising one Main GUI and several "Sub" GUIs. The Sub GUIs are opened from within the callbacks of the Main GUI in the following manner:
singleModesFig = SingleModesFig;
handlesSingleModesFig = guihandles(singleModesFig);
In this example, SingleModesFig is the name of a Sub GUI. In the OpeningFcn of SingleModesFig I modify the handles structure by appending some fields and try to save it back using guidata():
function SingleModesFig_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.treshold = 50;
handles.N = 1;
However, when entering any callback in the Sub GUI all the added fields (output, threshold, N,...) have disappeared:
function ExampleButton_Callback(hObject, eventdata, handles)
a = handles.treshold;
Interestingly, when I open the SingleModesFig not from code but manually by pressing "Run", guidata() works fine and the handles structure is saved back correctly. I tried to figure out the reason for this, but haven't found any sensible explanation. Does it create confusion for guidata if multiple figures are opened simultaneously? I tried to replace 'hObject' by an explicit search for the figure using its tag, but this doesn't solved the problem as well. In addition, I would rather like to understand this behavior and fix it than to incorporate workarounds using the base workspace.
I appreciate your hints and help.