필터 지우기
필터 지우기

Why is the pause button interfering with the exit button when pause is pressed?

조회 수: 1 (최근 30일)
So far I have the code below and need help with the button because it just pauses and will not continue and I can only press pause once per open Matlab.
function nightonearth
% NIGHTONEARTH shows rotating earth by night
% Requires images 'earth_lights_small.jpg' and
% 'moon.jpg' on the path stars=rand(100,2);
%Line 10 is for moon
[x,y,z] = sphere(48);
x2=(x*0.2734)+1;
y2=y*0.2734;
z2=z*0.2734;
f=figure('Color','k');
staraxis=axes('units','normalized','position',[0,0,1,1]);
scatter(stars(:,1),stars(:,2),'w.');
axis off
earthaxis=axes('units','normalized','position',[0,0,1,1]);
hold on;
s=surf(x,y,z);
s2=surf(x2,y2,z2);
%[X,Y]=meshgrid(0:2*pi/60:2*pi,(logspace(0,1,20)-1)./10);
%[X,Y]=pol2cart(X,Y);
%Z=X.^2+Y.^2;
%s3=surf(X,Y,Z);
shading interp
axis([-2.5,2.5,-2.5,2.5,-1.5,1.5]);
daspect([1,1,1])
axis off vis3d
set(gca,'Position',[0,0,1,1]);
topo=imread('earth_lights_small.jpg');
topoud=flipdim(topo,1);
set(s,'facecolor','texture');
set(s,'cdata', im2double(topoud));
[topomoon,map]=imread('moon.jpg');
set(s2,'facecolor','texture');
set(s2,'cdata', im2double(topomoon));
camtarget([0,0,0]);
campos([25,0,0]);
%------------------------------------------------------------------
% fig=figure;
tryme = uicontrol('Style','togglebutton','value', false, 'string', 'Exit');
%------------------------------------------------------------------
%IMPROVEMENT #2: Add another togglebutton to stop/restart the rotation
uicontrol('units', 'normalized', 'position', [.04 .1 .1 .05],...
'style', 'pushbutton', 'Callback', 'pause', 'string',
'Pause')
pause on
%^^^ just added this part
%------------------------------------------------------------------
while ~get(tryme, 'value')
rotate(s,[0,0,1],1,[0,0,0]);
rotate(s2,[0,0,1],0.0357,[0,0,0]);
% camorbit(15,0)
drawnow; pause(.1)
%------------------------------------------------------------------
end
close(f)

채택된 답변

Walter Roberson
Walter Roberson 2011년 4월 26일
You need a
pause on
call for the pause call in your IMPROVEMENT #2 to work. See http://www.mathworks.com/help/techdoc/ref/pause.html
When you have pressed the button, you need to press a key (not click again) for that form of pause to continue.
  댓글 수: 2
Aaron
Aaron 2011년 4월 26일
I added the pause on and it worked wonderfully, but when I go to press exit, it no longer works. Do you have any thoughts on this?
Aaron
Aaron 2011년 4월 26일
I think it just lagged up, but it seems to work now. I thank you so much for your help.

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

추가 답변 (1개)

Chirag Gupta
Chirag Gupta 2011년 4월 26일
You might be actually looking for uiwait and uiresume functionality instead of pause

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by