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 Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

질문:

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