필터 지우기
필터 지우기

Trying to control a simple "character bar spinner" with Start and Stop buttons

조회 수: 1 (최근 30일)
I would like to control the starting and stopping of the spinning action of the characters '| / - \' with Start and Stop buttons. In the below code, the Start button works just fine to start the spinning; but the Stop button (which I hoped would break the While loop, and thereby stop the spinning action) gives an error. Not sure why this is not working. Any illumination would be greatly appreciated. -Leith
handles.fig=figure;
handles.pb1=uicontrol('style','pushbutton','position',[100 200 100 40],'callback',@start_spin,'string','START');
handles.pb2=uicontrol('style','pushbutton','position',[250 200 100 40],'callback',@stop_spin,'string','STOP');
function start_spin(~,~)
idx=1;
j=1;
spin(idx,j);
end
function stop_spin(~,~)
j=0;
spin(idx,j);
end
function spin(idx, j)
ix = 1;
chars='|/-\';
while(idx==1)
if j==0
break;
end
fprintf(1,'\b%c', chars(ix));
ix = mod(ix,4)+1;
pause(0.05)
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by