MATLAB: Run a function when a GUI fig is opened

functionmatlab gui

Is it possible to automatically run a function when a GUI (fig) is opened? I.e. is there a property of the fig class that would do this? I would like to construct the controls differently depending on the environment, e.g. Windows vs. Linux, which specific files are in the system search path, etc. Thanks, Campbell

Best Answer

Use GUIDE. Then look at the m-file it creates. In there you'll find a function called yourgui_OpeningFcn(). You can place your code there and it will automatically get run when you launch your GUI. Check this out if you want to get up to speed fast: http://www.mathworks.com/matlabcentral/fileexchange/24224 It has a basic framework that is a good starting point for you to insert your code into various buttons, checkboxes, etc.
Related Question