Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Adoniram
Adoniram le 17 Juil 2020
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

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by