I need to break my while loop with a push of button but i get a error

3 vues (au cours des 30 derniers jours)
i got error message for my stop button.
Reference to a cleared variable a.
Error in apptest/captureButtonPushed (line 46)
while(a==true)
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 382)
Error while evaluating Button PrivateButtonPushedFcn.
function stopButtonPushed(app, event)
global a;
a=0;
end
% Button pushed function: captureButton
function captureButtonPushed(app, event)
global cam;
global a;
while(a==true)
I = snapshot(cam);
Bug = vision.CascadeObjectDetector('yes.xml');
bbox = Bug(I);
detectedImg = insertObjectAnnotation(I, 'rectangle', bbox, 'cat','FontSize',40);
detectedImg = insertShape(detectedImg, 'FilledRectangle',bbox,'Opacity',0.2,'LineWidth',5);
imshow(detectedImg,'Parent',app.UIAxes2);
pause(0.01);
end
end
end
  1 commentaire
Rik
Rik le 10 Nov 2020
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.

Connectez-vous pour commenter.

Réponse acceptée

Dennis
Dennis le 9 Nov 2020
Short answer: clear all; deletes a.
Longer answer:
Your immediate problem should be solved just by omitting the 'clear all'. Unless you want to specifically clear 'a' for some reason there is no point of the clear command in your function anyways. Functions have their own workspace, I cannot think of a good reason to put a 'clear all' in any function.
I'd also like to advice to not use global variables. There is usually a cleaner way; for example you could create a property a in your app and then use app.a instead of your global variable or use a toggle button and check the state of the button.
  7 commentaires
Dennis
Dennis le 13 Nov 2020
Please check if this works for you.
timothy lienanto
timothy lienanto le 15 Nov 2020
this works thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by