3

Why can't I compare specific types such as, function handles, using the == operation in Matlab?

For instance

@prod == @sum

fails with error

Undefined function 'eq' for input arguments of type 'function_handle'.

Does this mean that this type can support comparison if we just specify overload == for function_handle types?

Nordlöw
  • 11,838
  • 10
  • 52
  • 99

1 Answers1

6

To test equality of function handles, use the ISEQUAL command instead:

>> isequal(@prod, @sum)

ans =

     0

>> isequal(@prod, @prod)

ans =

     1
b3.
  • 7,094
  • 2
  • 33
  • 48
  • Thanks. Still, is there a reason for Matlab rejecting the use of `==' in this case? – Nordlöw Dec 08 '11 at 23:55
  • Figured you might ask again. I really don't know. I tend to use `isequal` more often and restrict `eq` for numeric data types. – b3. Dec 12 '11 at 23:47