force stop condition in a loop

조회 수: 1 (최근 30일)
liran avraham
liran avraham 2018년 7월 30일
편집: Dennis 2018년 7월 30일
can i add a condition in a loop that identify force stop (ctr+c) ? for example i control with matlab in a current source in a infinite loop (while(1)), and i want it to turn off when i stoped the loop with ctr+c for example: if force stop fprintf(device, ':OUTP OFF'); end

답변 (2개)

Dennis
Dennis 2018년 7월 30일
편집: Dennis 2018년 7월 30일
You can use onCleanup.Minimal exampel:
mytest()
function mytest()
finishup = onCleanup(@() mycleanup());
myloop();
end
function myloop()
while true
disp('running')
pause(1)
end
end
function mycleanup()
disp('stopped')
end
However maybe a loop that runs until a specific button is pressed is a cleaner approach.

KSSV
KSSV 2018년 7월 30일
HAve a look on break.
  댓글 수: 3
KSSV
KSSV 2018년 7월 30일
Whats the criteria for force stop?
liran avraham
liran avraham 2018년 7월 30일
the loop is some homemade temperature control, that why the loop is infinite, so i force break when i want to change the temperature or to stop measuring.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by