Execute Command every time any command is executed
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposte (1)
Jan
il 18 Lug 2017
Modificato: Jan
il 18 Lug 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.
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!