How can we know whether the current execution of command is conducting inside a function or not?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2021년 10월 23일
편집: Walter Roberson
2021년 10월 23일
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
추가 답변 (1개)
Image Analyst
2021년 10월 23일
편집: Image Analyst
2021년 10월 23일
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
Image Analyst
2021년 10월 24일
@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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!