In the general case, there is no way to detect whether a particular function has been called.
If you turn on profiling before you execute, then you can potentially examine the profile information to determine whether the function was called.
If the function happens to change state in a distinct way, such as creating a global variable, or opening a particular file, then you might be able to examine the program state to see if the function "must have been" called.
If the function is a .m file, then you could potentially put in a breakpoint in the file in order to determine whether the function was reached.
Usually the easiest way to deal with such matters is to create a flag variable that is initialized to false, with the program setting the flag to true immediately after calling the function. This requires the cooperation of the function.
2 Comments
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/575863-if-expression-to-check-whether-a-particular-function-has-been-called#comment_962404
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/575863-if-expression-to-check-whether-a-particular-function-has-been-called#comment_962404
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/575863-if-expression-to-check-whether-a-particular-function-has-been-called#comment_962464
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/575863-if-expression-to-check-whether-a-particular-function-has-been-called#comment_962464
Sign in to comment.