how to calculate cpu time

6 次查看(过去 30 天)
kash
kash 2013-3-20
I have a program
clc
if
%my program
else
disp('timed out')
end
my program consist of taking a snapshot through webcam
now i want to calculate the time,i.e the program must run for only 15 min,after 15 min if snapshot is taken it should be displayed as timed out

采纳的回答

Jan
Jan 2013-3-21
You cannot interrupt your program from the outside, but you need to check a flag or value inside the program. Usually this is done in loops like this:
tic;
while toc < 900 % 15 minutes
takeYourSnapShot;
end

更多回答(1 个)

Matt J
Matt J 2013-3-20
编辑:Matt J 2013-3-20
See commands tic, toc, etime, now, cputime, etc...
  3 个评论
Matt J
Matt J 2013-3-21
for example
T0=cputime;
for i=1:1e6
if i==1e6/2
T=cputime-T0, %The time half way through the loop
i,
end
end
kash
kash 2013-3-21
where i should insert my program

请先登录,再进行评论。

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by