MATLAB: Set uicontrol position relative to a subplot

guisubplotuicontrol

Is it possible to set the position of a GUI control element (e.g. a slider) relative to a subplot's position rather than relative to the whole figure?
The code I'm trying to write can have a variable number of subplots and it would easiest if I could set the uicontrol 'Position' relative to the subplot. For example, I might have two or three subplots and I want a slider under each of them.
Thanks!

Best Answer

No.
However, you can create a uipanel and the panel can contain axes and uicontrol such as sliders. uicontrol() 'Position' properties are relative to the container, not to the figure. axes cannot contain uicontrol, but uipanel can.
For example:
fignum = figure('Units', 'normal', 'Position', [0.1 0.1 .8 .8]); %not quite full screen
subgroup1 = uipanel('Parent', fignum, 'Units', 'normal', 'Position', [0 2/3 1 1/3]) %top third
subgroup1_plotbox = uipanel('Parent', subgroup1, 'Units', 'normal', 'Position', [0 .1 1 .9]) %plot in top 9/10 of the group
subgroup1_controls = uipanel('Parent', subgroup1, 'Units', 'normal', 'Position', [0 0 1 .1]); %control area in bottom 1/10 of the group
subgroup1_axes = axes('Parent', subgroup1_plotbox);
plot(1:50, rand(1,50), 'Parent', subgroup1_axes); %throw up some content
subgroup1_slider = uicontrol('style', 'slider', 'Parent', sugroup1_controls, ..... );
You do not actually need to create the two sub-panels for the above purpose, as you could put both the axes and the slider into 'Parent', subgroup1, making appropriate adjustments to the Position properties for those. The above example is for illustrative purposes, showing how you can create groups of objects in positional relationship to other groups of objects. You could resize the plot area and group of controls by adjusting the Position of the appropriate uipanel relative to the containing object. For simpler cases, that isn't worth the effort.
Each uipanel can act much like a figure (with some differences like not having individual toolbars), including uipanel being able to contain other uipanel.
Related Question