Is there a way to run a function every time Matlab returns to its command prompt

1 回表示 (過去 30 日間)
Ronan
Ronan 2011 年 5 月 20 日
I would like to install a function that would run every time any other function has completed.
This might be a bit like "startup.m" but would run every time the command prompt is shown instead of at startup. I know Matlab runs "rehash.m" in this manner so maybe there is a way to add more fcns to run at this time.
Is there a way to do this?
Thanks
Ronan
  2 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 5 月 20 日
What is the use case?
Ronan
Ronan 2011 年 5 月 20 日
I have a function which tracks usage of my other functions.
It does a much more comprehensive dependency analysis than is possible by code analysis. I would like this function to be able to know when all other functions have finished executing.
Thanks
Ronan

サインインしてコメントする。

回答 (2 件)

Jan
Jan 2011 年 5 月 20 日
A cheap method is to call all functions through a wrapper:
function varargout = wrapper(varargin)
varargout = cell(1, nargout)
[varargout{:}] = feval(varargin);
% Let the logging come here:
fprintf('returned at %s\n', datestr(now, 0));
Then you cannot just catch the return of the function, but the entry also.
Did you inspect the PROFILEr in detail? There are some undocumented features (look on Yair's pages).

Andy
Andy 2011 年 5 月 20 日
If you can get the handle to the command window (I'm sure Yair has done similar things at some point; take a look around www.undocumentedmatlab.com), then you can probably change the FocusGained callback to execute your code. But I don't know if this would overwrite the existing callback for the command window. (I also don't know if there is an existing callback, or what it does).
  1 件のコメント
Jan
Jan 2011 年 5 月 20 日
If you have an open GUI, the focus does not return to the command window, although all functions are ready.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by