force stop condition in a loop

5 次查看(过去 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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by