MATLAB: Have a figure slide under another

current figurefigurefigure slideMATLABposition;

Hi, I would like to have figure2 slide from behind figure 1 when I push a button. Unfortunately I was able to accoplish all that with exception of the sliding from behind. Each time I set the posiion it bring figure 2 to front and stays there. I know I can push figure 2 back behind figure 1 once I set the position however it does not look good or natural. Any ideas how to keep figure 2 behind the whole time? Thank you
figure 1
figure2('Visible','off')
figure(figure1)
for i = 1:65.2
set(figure2,'Position',[103.2+i 34.0769+10 62.8 15.6923])
end

Best Answer

I don't really understand why you would want to do this, but here you go:
Updated
function moveFigureElegantly
hFig1 = figure;
set(hFig1,'units','normalized');
plot(1:10);
hFig2 = figure;
surf(peaks);
%Where do we want to go
trajectory = [sin(linspace(0,2*pi,100)).', cos(linspace(0,2*pi,100)).']./2+0.25;
ii = 0; %Where are we
% NOTE keeping width and height fixed, they could be changed as well
T = timer('Period',0.5,... %period
'ExecutionMode','fixedRate',... %{singleShot,fixedRate,fixedSpacing,fixedDelay}
'BusyMode','drop',... %{drop, error, queue}
'TasksToExecute',200,...
'StartDelay',0,...
'TimerFcn',@moveFig,...
'StartFcn',[],...
'StopFcn',[],...
'ErrorFcn',[]);
start(T);
function moveFig(~,~)
% increment location
ii = ii+1;
%Move the figure
set(hFig1,'position',[trajectory(ii,:), 0.5 0.5])
% reset after looping through
if ii == size(trajectory,1)
ii = 0;
end
end
end
Related Question