---------- Forwarded message ----------
From:
Judd Storrs <address@hidden>
Date: Wed, Apr 22, 2009 at 10:28 PM
Subject: Re: Function handles for nonexisting functions
To: "John W. Eaton" <
address@hidden>
It behaves differently in different versions. The version I posted first was 7.5.0.338 R2007b (the newest version I have access to). In an older version R14sp1 student edition 7.0.1.24704 the behavior is different:
< M A T L A B >
Copyright 1984-2007 The MathWorks, Inc.
Version 7.5.0.338 (R2007b)
August 9, 2007
On Wed, Apr 22, 2009 at 10:14 PM, Judd Storrs
<address@hidden> wrote:
On Wed, Apr 22, 2009 at 8:50 PM, John W. Eaton
<address@hidden> wrote:
Create directories d1 and d2. Put the following fucntion in
d1/crash.m:
function crash ()
'd1/crash'
and put the following function in d2/crash.m:
function crash ()
'd2/crash'
Now start Matlab in the directory that contains d1 and d2, and run the
following commands:
fh = @crash
fh ()
cd d1
fh ()
cd ../d2
fh ()
EDU>> fh = @crash
fh =
@crash
EDU>> fh ()
??? Undefined function or variable 'crash'.
EDU>> cd d1
EDU>> fh ()
??? Undefined function or variable 'crash'.
EDU>> cd ../d2
EDU>> fh ()
??? Undefined function or variable 'crash'.
clear all
fh = @crash
cd ..
fh ()
cd d1
fh ()
EDU>> clear all
EDU>> fh = @crash
fh =
@crash
EDU>> fh ()
ans =
d2/crash
EDU>> cd ..
EDU>> fh ()
ans =
d2/crash
EDU>> cd d1
EDU>> fh ()
ans =
d2/crash
Now, while Matlab is still running, change the definition of
d2/crash.m to be
function crash ()
'foo'
and then continue your Matlab session with the following commands:
fh ()
cd ..
fh ()
cd d2
fh ()
EDU>> fh ()
ans =
d2/crash
EDU>> cd ..
EDU>> fh ()
ans =
d2/crash
EDU>> cd d2
EDU>> fh ()
ans =
foo
clear all
addpath (pwd)
cd ..
fh = @crash
fh ()
EDU>> clear all
EDU>> addpath(pwd)
EDU>> cd ..
EDU>> fh = @crash
fh =
@crash
EDU>> fh ()
ans =
foo
Now, while Matlab is still running, change the definition of
d2/crash.m to be
function crash ()
'bar'
and then continue your Matlab session with the following commands:
fh ()
cd d1
fh ()
cd ../d2
fh ()
EDU>> fh ()
ans =
bar
EDU>> cd d1
EDU>> fh ()
ans =
bar
EDU>> cd ../d2
EDU>> fh ()
ans =
bar