Execute Command every time any command is executed
2 次查看(过去 30 天)
显示 更早的评论
This might be a weird question. I am looking for some way to always execute a command/script BEFORE any script is being executed.
More specifically, I want to know the time when the root of the calling stack has been called. I know, that in principle I can do this with 'tic' and 'toc'. But I do not want to place tic and toc at the beginning of every function/script/command prompt I call... Is there a way of doing this? E.g. event trigger?
1 个评论
回答(1 个)
Jan
2017-7-18
编辑:Jan
2017-7-18
Running a "script BEFORE any script is being executed" is a contradiction and the direct implementation would cause an infinite recursion.
The wrapper mentioned by Adam can look like this:
function varargout = myStart(fcn, varargin)
tic
[varargout{1:nargout}] = fcn(varargin{:});
end
Now start you function not as
yourFcn(1, 2, 'hello')
but as
myStart(@yourFcn, 1, 2, 'hello')
You could attach a listener to the status message of the CommandWindow, which displays 'busy' during computations. Perhaps some details from FEX: CmdWinTool might be useful. But I would not create such indirect triggers. It is meta-programming to parse the screen output of Matlab to detect a certain event. Better insert the tic exactly where you need it and not by a magic tricks.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!