Deleting CreateFcn from GUI .m file

I have finished creating GUI and since I have a lot of objects my .m-file is quite long, mainly because there is a lot of
function name_CreateFcn(hObject, eventdata, handles)
I thought I can delete these CreaterFcn since I dont use then, only Callbacks, but when I deleted them and run the program I am receiving an error for each object:
Error using feval Undefined function 'name_CreateFcn' for input arguments of type 'matlab.ui.control.UIControl'.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in GUI (line 16) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI('name_CreateFcn',hObject,eventdata,guidata(hObject))
Is it possible then to delete these CreateFcn without receiving error, or they must remain in the code?

 Risposta accettata

Adam
Adam il 5 Set 2016

1 voto

Yes, you can delete them, and I almost always do, but you must also clear the field in the corresponding graphics object within GUIDE.
So you will find a CreateFcn property field and you can just delete what is in here.
I also do the same thing for the Callback property field in cases where I do not want a callback.

6 Commenti

Thank you
Thanks a lot.
When i try to delete "function name_CreateFcn(hObject, eventdata, handles)" in the Create_Fcn field in GUIDE , then it automatically comes back and i do not get it deleted.
Is there any solution to that?
@Anand Parikh: Press 'Enter' after deleting the whole line in the property inspector (don't just mouse-click out of the row). Only then you can close the window of the inspector and have the change in effect. Later when you save the .fig file from GUIDE, it will be written out correctly.
Thanks a lot!
Voss
Voss il 18 Mag 2022
There is an option in GUIDE (in the Tools menu > GUI Options ...) called "Generate callback function prototypes", which is selected by default. De-selecting this option will prevent CreateFcns and Callbacks from being generated in the first place.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Printing and Saving in Centro assistenza e File Exchange

Richiesto:

il 5 Set 2016

Commentato:

il 18 Mag 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by