当前位置: 代码迷 >> 综合 >> matlab实现程序计时功能
  详细解决方案

matlab实现程序计时功能

热度:42   发布时间:2024-02-24 11:37:04.0

本次我们使用tic

t1 = clock;//程序的位置t2 = clock;t = etime(t2-t1);
disp(htime(t));

其中htime的实现如下:也可以添加任何其他形式!!!

function htime = htime(sec)
%   HTIME_STRING = htime(SECONDS)if isnan(sec)htime = '?';elseif sec < 1 * 60  % max 1 minutehtime = [num2str(sec, '%.1f') 's'];elseif sec < 1 * 60 * 60 % max 1 hour htime = [num2str(sec/60, '%.1f') 'm'];elseif sec < 2 * 60 * 60 * 24 % max 2 dayshtime = [num2str(sec/60/60, '%.1f') 'h'];elseif sec < 1 * 60 * 60 * 24 * 365 % max 1 yearhtime = [num2str(sec/60/60/24, '%.1f') 'd'];elsehtime = [num2str(sec/60/60/24/365, '%.1f') 'r'];end
end

 

  相关解决方案