How can we know whether the current execution of command is conducting inside a function or not?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Saang Bum Kim
le 23 Oct 2021
Commenté : Image Analyst
le 24 Oct 2021
How can we know whether the current execution of command is conducting inside a function or not?
When I develop a function, I frequently check some parts of the code for the function in base command envirenment.
I wonder is there any method to identify whether the current execution is conducting inside of a function or
it is conducting in the base environment.
Thanks in advance !!!
0 commentaires
Réponse acceptée
Walter Roberson
le 23 Oct 2021
Modifié(e) : Walter Roberson
le 23 Oct 2021
The functions nargin and nargout will error if executed at the base. So you can use try/catch
inbase = false; try; nargin; catch ME; inbase = true; end
0 commentaires
Plus de réponses (1)
Image Analyst
le 23 Oct 2021
Modifié(e) : Image Analyst
le 23 Oct 2021
You can call fprintf immediately upon entering and just befor leaving the function:
fprintf('Entering MyFunction().\n');
fprintf('Leaving MyFunction().\n');
If you stop at a break point, you can check the call stack on the tool bar. Or you can get the call stack from my attached function and print it out inside the function.
5 commentaires
Image Analyst
le 24 Oct 2021
@Saang Bum Kim, okay. I don't see Stephen on this thread, but it looks like you've accepted the Answer from Walter so I guess everything is figured out and working now. Best wishes.
Voir également
Catégories
En savoir plus sur Historical Contests dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!