MATLAB: Able to run GUI from guide command interface, but not when opening .fig straight in folder

callback errorguiguide

after typing in "guide" in the command window and then opening an existing GUI, and then using the GUI editor and pressing "Run Figure (Ctr+T)," everything works fine (no error). However, when opening the GUI directly by double clicking the .fig file in the windows explorer, and attempting to execute by pressing on my pushbuttons I get the following error in the command window:
??? Attempt to reference field of non-structure array.
Error in ==> GUI_CompSurf>ParaRest_dir_browse_Callback at 154
set(handles.Data_dir_label,'String',parameter_restrictions)
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI_CompSurf at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)GUI_CompSurf('ParaRest_dir_browse_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
When debugging, the error seems to be at a set() command:
data_directory = uigetdir(pwd,'Select Data Directory, where your datas are located');
set(handles.Data_dir_label,'String',data_directory) %<---error here
"Data_dir_label" is static text that show the directory string, at least it should.
If anyone has any idea, it would be most appreciated.
Thank you.

Best Answer

I do not know if opening the figure by double clicking on it would invoke the Figure Open Callback, but surely opening the figure under those circumstances would invoke the Figure Resize Callback. So you can stuff code in there that detects whether the GUI has been initialized properly, and initializes it if not.
There are some tricky spots to doing this, but it should be possible in theory.