Home MATLAB gui: Execute code before CreateFcns
Reply: 2

MATLAB gui: Execute code before CreateFcns

Arne
1#
Arne Published in 2018-02-14 10:03:45Z

I'd like to execute some code before the CreateFcns are called (e.g. from textbox, pop menus etc), because my CreateFcns rely on some struct data, which that specific code would fill in.

It seems that the functions are called in that order:

- CreateFcn 1
- Init Fcn
- CreateFcn 2
- Init Fcn
...
- CreateFcn n
- Init Fcn
- OpeningFcn
- Init Fcn

Is there a way to execute some code before the first CreateFcn? As the newest CreateFcn is called always first, the workaround to put the code in the first CreateFcn is extremely unhandy as you need to change the code everytime you add a new textbox etc. to the gui.

Will
2#
Will Reply to 2018-02-14 12:25:10Z

The figure containing the controls also has a CreateFcn. This is called before the CreateFcns for the child control.

Ensure GUIDE has generated and assigned a CreateFcn to the figure by right-clicking the figure background and choosing View Callbacks > CreateFcn. Any initialization code depended on by the child controls should be added to this function.

Arne
3#
Arne Reply to 2018-02-14 13:03:14Z

As @Will pointed out correctly, the right way is to write the code in the create function of the figure itself as this one is always called first.

Just add this to the code

function figure1_CreateFcn(hObject, eventdata, handles)
% Code here will be executed first before all other functions
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.325279 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO