Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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

Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by