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)
Afficher commentaires plus anciens
timothy lienanto
le 9 Nov 2020
Commenté : timothy lienanto
le 15 Nov 2020
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
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.
Réponse acceptée
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!