I need to break my while loop with a push of button but i get a error
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Rik
2020년 11월 10일
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
채택된 답변
Dennis
2020년 11월 9일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!