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?

 採用された回答

Adam
Adam 2016 年 9 月 5 日

1 投票

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 件のコメント

Jakub F
Jakub F 2016 年 9 月 5 日
Thank you
Arnab Das
Arnab Das 2018 年 1 月 2 日
Thanks a lot.
Anand Parikh
Anand Parikh 2018 年 11 月 28 日
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?
luke12cz
luke12cz 2018 年 11 月 29 日
@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.
付 凡
付 凡 2022 年 5 月 18 日
Thanks a lot!
Voss
Voss 2022 年 5 月 18 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePrinting and Saving についてさらに検索

質問済み:

2016 年 9 月 5 日

コメント済み:

2022 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by