MATLAB: Creating separate instances of a custom GUIDE figure and access ui elements inside

figureguideui

I created a custom figure with GUIDE that I want to create multiple instances of. Each custom figure contains 3 sliders and a set of axes. I want to treat that custom figure as an object and then fig1 = new customFigure() fig2 = new customFigure() etc. I also want to be able to access the child components inside each custom figure so for example I want to be able to read fig2.slider1.Value from my main program file and have that be a different instance than fig1.slider1.Value. (As an aside, my background is C and Java so I don't fully understand how MatLab is working here)

Best Answer

Open your file with GUIDE(). When the GUIDE interface opens displaying your figure, right click anywhere on the figure background (ie, not on a GUI component). Then select GUIoptions. Make sure the checkbox "GUI allows only one instance to run" is unchecked. Save and close the GUIDE interface and any existing versions of your GUI.
Let's say your GUI is named "myGUI.m". You can open as many instances as you'd like by executing :
f1 = myGUI;
f2 = myGUI;
f1 and f2 will be handles to each figure and you can use that to get the other handles within each figure.