Able to run GUI from guide command interface, but not when opening .fig straight in folder
18 views (last 30 days)
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
Error in ==> gui_mainfcn at 96
Error in ==> GUI_CompSurf at 42
Error in ==>
??? 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.
Walter Roberson on 30 Sep 2011
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.
More Answers (5)
Fangjun Jiang on 30 Sep 2011
I can repeat what you did and got the same error. I didn't a quick debug and it seems that the GUI is not properly initialized. Then I did a search and found the following link. See the last paragraph. It is suggest ed not to double-click the .fig file to open the GUI.
If you really like to have this "double-click" to run the application capability, I can think of:
- Compile the .m file to .p file and double-click the .p file
- Change the settings of MATLAB so you can double-click the .m file to run the .m file, instead of edit the .m file. I remember there is a QA on this forum for that.
- Compile your GUI application to an .exe file. You'll need to have the MATLAB Compiler Toolbox.
Vlad Atanasiu on 10 May 2015
You could use a double-click on the thefig.fig file to run your GUI if you include in it a call to the function thefig_OpeningFcn of the thefig.m file. This way the GUI is reading all the setup information it needs, i.e. from both .fig and .m files.
Note that you need to leave the GUI sufficient time to update before being able to use it. The call to thefig_OpeningFcn might be hidden in a button that doesn't need data defined in thefig_OpeningFcn. In that case, to get the GUI running, you double click on thefig.fig, followed by a click on the special button.
Harris Yong on 15 Sep 2016
Is there a way to disable the GUI from even opening when double-clicking on the .fig? That'd force people to open it some other way.
MUKHTAR MANSURI on 17 Sep 2018
My gui is working properly when using with matlab and even after compilation in my laptop.. But when I install this executive file in others laptop it is showing error (error in line 42, which is main function line (not editable) in my matlab code ). I have compiled many times my code, but it is showing the same error in others laptop. Help to install my code for public domain.