Able to run GUI from guide command interface, but not when opening .fig straight in folder
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Quy
il 30 Set 2011
Commentato: Walter Roberson
il 19 Set 2018
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.
4 Commenti
Risposta accettata
Walter Roberson
il 30 Set 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.
2 Commenti
Jan
il 10 Mag 2015
Alternatively the WindowButtonMotionFcn is called also, when the user moves the mouse into the figure.
Jake G
il 27 Mag 2016
Thank you for the help! However...I have a close request function so if I accidentally open it by double clicking the fig file when I meant to open it in GUIDE I have to close all of Matlab to get rid of the windows :(
Più risposte (5)
Fangjun Jiang
il 30 Set 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.
2 Commenti
Vlad Atanasiu
il 10 Mag 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.
2 Commenti
Jan
il 10 Mag 2015
Instead of using the manually triggered callback of a button, The ResizeFcn as suggested by Walter is called automatically when the fig-file is opened by a double click. The WindowButtonMotionFcn might be useful also, because it can be assumed that it is called before any other interaction by the user.
Walter Roberson
il 19 Set 2018
thefig_OpeningFcn is not called if you open the fig file directly. The OpeningFcn is called by the prolog code that GUIDE inserts that is only invoked if the .m file is run.
Harris Yong
il 15 Set 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.
2 Commenti
Image Analyst
il 16 Set 2016
Before the line where it says
% Begin initialization code - DO NOT EDIT
put this code:
if nargin ~= 0
close gcf;
return;
end
% Begin initialization code - DO NOT EDIT
You can also craft an error message and display it if you want, before the return:
errorMessage = sprintf('You cannot.......
uiwait(errordlg(errorMessage));
return;
Walter Roberson
il 19 Set 2018
I would tend to think that should be "nargin == 0" rather than "nargin ~= 0"
MUKHTAR MANSURI
il 17 Set 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.
1 Commento
Walter Roberson
il 19 Set 2018
(You created https://www.mathworks.com/matlabcentral/answers/419319-error-error-in-line-42-in-using-matlab-execution-guide-compiled-file for this question)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!