本次我们使用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