How do I use pre-defined data in *_CreateFcn calls in GUIDE?

2 views (last 30 days)
Hello,
I am a self-described 'modest' Matlab programmer and have recently started coming back up to speed on GUIDE for my work.
My situation is that I have roughly three dozen components on my GUI, and I would like to have a large number of them initialized based on 'pre-defined' data that I have hard-coded somewhere in a central location. I say central as I would like to use some pieces of data be used to initialize multiple components. A quick example of what I want is if I had two text boxes on my GUI:
function text_box1_CreateFcn(hObject, eventdata, handles)
set(hObject, 'string', handles.paramA)
function text_box2_CreateFcn(hObject, eventdata, handles)
set(hObject, 'string', handles.paramA)
Where handles.paramA has been set 'before' the code gets to this point.
Further Discussion
I know that I can do what I want by setting both text boxes in the OpeningFcn() function with:
set(handles.text_box#, 'string', handles.paramA)
but you can imagine that OpeningFcn() would get quite large as I have significantly more than two components to set, and some of the initialization I am doing involves blocks of logic rather than just single lines. Is this route my best bet? I think the crux of my problem is that all CreateFcn() calls are executed before OpeningFcn(), correct?
  2 Comments
Aaron
Aaron on 24 Nov 2015
My apologies to the admins: I just realized that the title of this thread and the discussion/answer therein are somewhat disjointed. I will accept whatever sage wisdom you have should this issue need to be rectified.
Aaron
Aaron on 24 Nov 2015
I am satisfied with the answer though (i.e. don't use _CreateFcn).

Sign in to comment.

Accepted Answer

Adam
Adam on 24 Nov 2015
I would say yes you have to do it from the OpeningFcn, but that doesn't mean all the code has to be in the OpeningFcn.
My OpeningFcn in Uis tends to call a string of other functions like
initialiseSomeSliders( handles )
initialiseSomeOtherSliders( handles )
initialiseAxes( handles )
Obviously you can delegate to as many or as few functions as you like and my functions often further delegate anyway so the OpeningFcn usually stays tidy and relatively short.
I don't used the createFcn's myself (I even delete them all if I can be bothered), but I would imagine that they get called before OpeningFcn so you can't access data attached to handles in them, only the handles of other UI components.

More Answers (0)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!