How to tell if a function was called from within Matlab or from system?

12 ビュー (過去 30 日間)
Chris Angeloni
Chris Angeloni 2021 年 2 月 17 日
コメント済み: Walter Roberson 2021 年 2 月 20 日
I've been running Matlab code on a high performance cluster, but while debugging it is useful to run it in an interactive matlab instance for plotting and such. However, I would want my code to do different things when called from the cluster compared to when it's called interactively in the matlab GUI. My specific case is using bash to call my matlab function in a unix-based cluster.
Is there a way to programmatically determine from which environment a Matlab function was called from?

回答 (2 件)

John D'Errico
John D'Errico 2021 年 2 月 17 日
Perhaps you might try what are essentially different calls, where you pass information about WHERE your call is coming from. So subtly different calls to the same function, but one of the arguments to that function is now an indicator variable that will change the behavior of the function.

Walter Roberson
Walter Roberson 2021 年 2 月 17 日
isunix() will be true on the cluster, or on desktop Linux or Mac systems, but not on Windows systems.
If your desktop is Mac, then ismac() is true. Contrawise, isunix() && ~ismac() implies linux()
When isunix() is true,
HN = system('hostname')
would permit you to differentiate between different Linux hosts you run the code on.
  2 件のコメント
Chris Angeloni
Chris Angeloni 2021 年 2 月 19 日
Thank you for the suggestion! I didn't describe the problem well enough I think:
In both cases, I am running code on a unix cluster, but in the main use case, I am running it through bash calls that queue the code to run on compute nodes. In the debugging case, I am 'pressing play' in the matlab GUI that is running on the same cluster. This may be addressed by
system('hostname')
Walter Roberson
Walter Roberson 2021 年 2 月 20 日
Set an environment variable in the bash script and in the matlab code check the environment variable with getenv()?

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

カテゴリ

Help Center および File ExchangePlatform and License についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by