Break A While loop using a status Button

3 vues (au cours des 30 derniers jours)
Mohamed Afify
Mohamed Afify le 15 Juil 2021
Commenté : Mohamed Afify le 19 Juil 2021
Hello, I am trying to break the while loop containing that for loop by using the 1 and 0 status of the status button. I am having an issue doing it. That's my code below. Any other ideas to break a while 1 loop would be appreciated. Thank you!
% Value changed function: CANSTARTButton
function CANSTARTButtonValueChanged(app, event)
value = app.CANSTARTButton.Value;
app.CANSTARTButton.Value = 0;
app.CANSTARTButton.Enable = true;
while 1
%add code here
app.CANMSGStatusLamp.Color = 'Blue';
for v = 1.0:-0.2:0.0
disp(v)
end
%%end
if (app.CANSTARTButton.Value == 1)
app.CANMSGStatusLamp.Color = 'red';
break;
end
end
app.CANSTARTButton.Value = 0;
app.CANSTARTButton.Enable = false;
%if (value==1)
% app.CANMSGStatusLamp.Color = 'red';
% while 1
%else
% app.CANMSGStatusLamp.Color = 'Green';
%end
end
end

Réponses (1)

Jan
Jan le 15 Juil 2021
Modifié(e) : Jan le 15 Juil 2021
Insert a drawnow command inside the loop to let Matlab update the GUI.
A small simplification:
app.CANMSGStatusLamp.Color = 'Blue';
while app.CANSTARTButton.Value == 0
%add code here
for v = 1.0:-0.2:0.0
disp(v)
end
drawnow;
end
app.CANMSGStatusLamp.Color = 'red';
  1 commentaire
Mohamed Afify
Mohamed Afify le 19 Juil 2021
Never knew about the drawnow, worked fine thank you so much!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by