The right way is indeed by means of a
is* function, namely
if isa(f, 'function_handle')
% f is a handle
% f is not a handle
For completeness, I'd like to point out that using
class() works for checking if something is a function handle.
isa, this doesn't generalize well to other aspects of MATLAB such as object-oriented programming (OOP) that are having an increasing impact on how MATLAB works (e.g. the plot functionality, the control toolbox, the identification toolbox, ... are heavily based on OOP).
For people familiar with OOP:
isa also checks the super types of the
x object for
strcmp(class(x), 'someClass') obviously only checks for the exact type.
For people who don't know OOP: I recommend to use
isa(x, 'someClass') instead of
strcmp(class(x), 'someClass') as that is the most convenient (and common) behavior of the two.