On Wed, Nov 9, 2011 at 11:01 AM, Richard<address@hidden> wrote:
On 09/11/2011 08:18, Dr. Alexander Klein wrote:
Good morning,
is there any preferred way to check whether a given parameter or variable
contains a function handle?
I find myself strcmp'ing the result of typeinfo quite often, but this is
really clumsy. Then again, ishandle only checks for graphics handles ...
Best regards,
Alex
if it is octave code you can use the 'isa' function e.g.
isa(@sin, 'function_handle')
but maybe I'm misunderstanding and you mean in the C++ sources or something.
Richard
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
Checking
f = @(x)x;
n=5e4;
t0=cputime;
for i=1:n
strcmp(typeinfo(f),'function_handle');
end
t=cputime-t0
t0=cputime;
for i=1:n
isa(f,'function_handle');
end
t=cputime-t0
I get
t = 1.0521
for strcmp
t = 5.0083
for isa
Is the benchmark correct?