uistack

Reorder visual stacking order of objects

Syntax

uistack(h)
uistack(h,stackopt)
uistack(h,stackopt,step)

Description

uistack(h) shifts object h up one level within the visual stacking order of UI objects. You can also specify h to be a vector of UI objects. When h is a vector, the objects stack according to their order in the vector. All items in the stack must share the same parent.

uistack(h,stackopt) moves the object h to another place in the stack according to stackopt:

  • 'up' – moves h up one position in the stacking order

  • 'down' – moves h down one position in the stacking order

  • 'top' – moves h to the top of the current stack

  • 'bottom' – moves h to the bottom of the current stack

uistack(h,stackopt,step) moves object h up or down the number of levels specified by step. For example, uistack(h,'up',2) moves h up two levels in the stack.

Examples

expand all

Change Stacking Order of Two Plots in a Figure

Create a figure containing a uipanel and a child axes. Then, plot a sine function in the axes.

f = figure;
p1 = uipanel(f,'Position',[.10 .10 .80 .80],...
            'Tag','Panel with Sine Plot');
ax1 = axes('Parent',p1,'Position',[.1 .1 .8 .8]);

theta = -3*pi:pi/64:3*pi;
y1 = sin(theta);
plot(ax1,theta,y1);

In the same figure, create a second uipanel with a child axes. Then, create a surface plot in this axes.

p2 = uipanel(f,'Position',[.10 .10 .80 .80],...
            'Tag','Panel with Surface Plot');
ax2 = axes('Parent',p2,'Position',[.1 .1 .8 .8]);
Z  = peaks(25);
surf(ax2,Z);

Next, move the uipanel containing the sine function to the top.

uistack(p1,'top');
f.Children
ans = 

  2x1 Panel array:

  Panel    (Panel with Sine Plot)
  Panel    (Panel with Surface Plot)

Now, move the other uipanel to the top.

uistack(p2,'top');
f.Children
ans = 

  2x1 Panel array:

  Panel    (Panel with Surface Plot)
  Panel    (Panel with Sine Plot)

Was this topic helpful?