have a figure slide under another

조회 수: 1 (최근 30일)
Vincent I
Vincent I 2013년 6월 24일
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

채택된 답변

Sean de Wolski
Sean de Wolski 2013년 6월 24일
편집: Sean de Wolski 2013년 6월 25일
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
  댓글 수: 2
Vincent I
Vincent I 2013년 6월 25일
well, it still brings the figure 2 on top of figure 1 when I make it visible with the code below. I think what I'm going to do is use your idea to make it work. Thank you
Sean de Wolski
Sean de Wolski 2013년 6월 25일
See the edits. Now it follows a trajectory. There are a few different ways you can do this; personally I like nested functions for this application.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Evan
Evan 2013년 6월 24일
편집: Evan 2013년 6월 24일
Does this work?
% Example
f = figure; % create first figure
g = figure; % create second figure (appears in front of first)
figure(f) % bring first figure to front
I tried out your example, and calling the figure that should be "in front" like I did above inside the loop seemed to do the trick.
  댓글 수: 6
Vincent I
Vincent I 2013년 6월 24일
My appologies....
No, figure1 should stay in front of figure 2 the whole time figure 2 is moving to the right.
what I mean is the figure that I already have do look really choppy and yeah they do flicker.
Evan
Evan 2013년 6월 24일
Hmm, interesting. My way is certainly crude, though I don't experience any noticeable flicker due to the "bring to front." Perhaps Sean's solution will work for you.

댓글을 달려면 로그인하십시오.


Vincent I
Vincent I 2013년 6월 24일
solved it by doing the following:
figure1
t=figure2
figure(figure1)
for i=1:63
set(t,'Position',[])
end
the initial problem was that instead of setting the handle I was setting the position of the figure itself. Works now
Thank you for your help

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by