Trying to control a simple "character bar spinner" with Start and Stop buttons
2 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!