我有这个功能:
function example(y)
global TICTOC;
tic
TICTOC=5;
toc
end
我希望TICTOC=5改变toc的结果,因为TICTOC是 tic 和 toc 函数中的全局变量;但这种情况并非如此; 有谁知道原因?
我想知道答案,因为我担心声明一个全局变量,它的名称已在其他一些函数中声明为全局变量,我不知道。
我在 matlab 2008b 帮助中看到了这个函数
function tic
% TIC Start a stopwatch timer.
% TIC; any stuff; TOC
% prints the time required.
% See also: TOC, CLOCK.
global TICTOC
TICTOC = clock;
function t = toc
% TOC Read the stopwatch timer.
% TOC prints the elapsed time since TIC was used.
% t = TOC; saves elapsed time in t, does not print.
% See also: TIC, ETIME.
global TICTOC
if nargout < 1
elapsed_time = etime(clock, TICTOC)
else
t = etime(clock, TICTOC);
end
谢谢。