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?

 Accepted Answer

Adam
Adam on 5 Sep 2016
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 Comments

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!
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Asked:

on 5 Sep 2016

Commented:

on 18 May 2022

Community Treasure Hunt

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

Start Hunting!