我有这样的功能:我们可以重写全局变量吗?
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
感谢这个功能。
euhm ...你有什么Matlab版本?至少从R2010b(意思是说,没有Matlab可访问的全局变量),TICTOC一直是一个内置函数... –