Question: In Matlab, how can I check if a function handle is a particular function or function type?
Example: Let f1
be a function handle. How do I check if f1
is the in-built Matlab function mean
? How do I check if f1
is an anonymous function?
My Current Solution: My current solution to this problem involves a call to the functions
function. functions
accepts a function handle as input and returns a structure containing information about the input function handle, eg function type, path, function name etc. It works, but it is not an ideal solution because, to quote the official documentation:
"Caution MATLAB® provides the functions
function for querying and debugging purposes only. Because its behavior may change in subsequent releases, you should not rely upon it for programming purposes."
f1
as one of its inputs, I am able to take certain short-cuts iff1
is one of a number of recognized functions, such as a sample mean etc. However, I also want the function to work for other types of functionsf1
where such short-cuts are impossible. Does this make sense? – Morvillecellfun
face the same issue as you, and solve the issue by allowing both function handles and a limited set of string arguments in the same place, providing an alternative and faster code path for the preset strings. Just a thought. – Misti