Execute Command every time any command is executed
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Respuestas (1)
Jan
el 18 de Jul. de 2017
Editada: Jan
el 18 de Jul. de 2017
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.
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!