From: Matt J on 8 Feb 2010 12:08 The help doc on isequal() does not say how it treats function handles. Experimentation shows inconsistent results, however: >> isequal(@sin,@sin) ans = 1 >> isequal(@(x)x+1,@(x)x+1) ans = 0 Does anyone know why the case of anonymous functions does not work? Since an error was not thrown, I assume isequal is meant to do something reasonable with function handle input.
From: Oleg Komarov on 8 Feb 2010 12:23 "Matt J " > The help doc on isequal() does not say how it treats function handles. Experimentation shows inconsistent results, however: > > >> isequal(@sin,@sin) > > ans = > > 1 > > >> isequal(@(x)x+1,@(x)x+1) > > ans = > > 0 > > Does anyone know why the case of anonymous functions does not work? Since an error was not thrown, I assume isequal is meant to do something reasonable with function handle input. Same 'inconsistency' found on Win server2008 64bit Mat2009b Oleg
From: Peter on 8 Feb 2010 12:24 On Feb 8, 9:08 am, "Matt J " <mattjacREM...(a)THISieee.spam> wrote: > The help doc on isequal() does not say how it treats function handles. Experimentation shows inconsistent results, however: > > >> isequal(@sin,@sin) > > ans = > > 1 > > >> isequal(@(x)x+1,@(x)x+1) > > ans = > > 0 > > Does anyone know why the case of anonymous functions does not work? Since an error was not thrown, I assume isequal is meant to do something reasonable with function handle input. Here is my rationale as to why the results you obtained are actually consistent... In the first test, you generated a pair of handles, both of which point to the same built-in function, and both of which are therefore considered equal. For your second example, Matlab has no way of knowing that the two anonymous functions are identical. Each will be individually encapsulated. Since the two handles do not point to the same regions of memory, they are therefore considered not equal. The following example: >> h1 = @(x) x^2 + 1 h1 = @(x)x^2+1 >> h2 = h1 h2 = @(x)x^2+1 >> isequal(h1,h2) ans = 1 shows that h1 and h2 are considered equal if they both reference the same anonymous function definition, as you would expect. HTH, --Peter
From: Matt J on 8 Feb 2010 13:16 Peter <petersamsimon2(a)hotmail.com> wrote in message <6a8e4b21-8a4b-49f9-8e36-7bf5ecd60826(a)b7g2000yqd.googlegroups.com>... > Since the two handles do not point to the > same regions of memory, they are therefore considered not equal. ================ That doesn't quite rationalize it for me. ISEQUAL is supposed to examine the contents of the variables, not just the region of memory they occupy. In the following simple example, a and b do not point to the same memory either, yet isequal correctly judges they as equal. >> a=1;b=1; isequal(a,b) ans = 1
From: Oleg Komarov on 8 Feb 2010 13:31
"Matt J " > Peter > > > Since the two handles do not point to the > > same regions of memory, they are therefore considered not equal. > ================ > > That doesn't quite rationalize it for me. ISEQUAL is supposed to examine the contents of the variables, not just the region of memory they occupy. In the following simple example, a and b do not point to the same memory either, yet isequal correctly judges they as equal. > > >> a=1;b=1; isequal(a,b) > > ans = > > 1 I think clarification from TMW is needed here. I see it as an inconsistency. Oleg |