MATLAB 函数:返回自首次函数调用以来经过的时间
这个简单的 MATLAB 函数可用作挂钟式经过时间提供器,例如用于 Simulink 模型。它返回自首次调用该函数以来经过的时间(以秒为单位)。
elapsed_time_since_first_call.m
function t = elapsedTime()
%ELAPSEDTIME 返回自首次调用以来的挂钟秒数。
% t = ELAPSEDTIME() 返回自首次调用该函数以来经过的秒数(挂钟时间)。
persistent t0
if isempty(t0)
t0 = tic; % 在首次调用时启动计时器
end
t = toc(t0); % 自首次调用以来经过的时间
end你可以在 MATLAB 或 Simulink 模型中使用此函数:

Check out similar posts by category:
MATLAB/Simulink
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow