Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: M files must be run twice for changes to take effect on linux
Date: Mon, 2 Mar 2009 15:09:01 +0000 (UTC)
Organization: University of Michigan
Lines: 64
Message-ID: <gogsqd$pbe$1@fred.mathworks.com>
References: <fcul58$kac$1@fred.mathworks.com> <fd0hqp$4s2$1@fred.mathworks.com> <fiqr4h$44t$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236006541 25966 172.30.248.38 (2 Mar 2009 15:09:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 2 Mar 2009 15:09:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1544408
Xref: news.mathworks.com comp.soft-sys.matlab:521887


I had exactly this same problem (R2008b on mac), where I wrote a .m file as output from a script, and then ran it both using the "run" command and by opening it up in the editor and choosing "Run...". The only way it would recognize the change was to either modify the .m script in the editor (even if the "new" file was written), or to use the "clear functions" command.

Matlab ought to at least check the modification dates of files it runs to determine whether it can use cached versions. Having to know about and exectue "clear functions" is not acceptable.

It's fortunate that I found this thread about MATLAB's buggy m-file running behavior. Hopefully others encountering this problem will be able to find this solution, too.  If nothing else, the help for 'run' should include something about this.

"Tim " <timtjanssen@yahoo.com> wrote in message <fiqr4h$44t$1@fred.mathworks.com>...
> Thanks all for the input. Sorry for not getting back sooner.
> Yes, with 'clear functions' problem is solved. I actually
> was already using that. However, I don't understand why I
> should use that, when I never had to before.
> 
> It turns out that the problem occurs with functions that are
> in a different directory than from which I'm working
> (running the primary script). For some of my programs I have
> functions in subdirectories that I usually don't add to the
> path, but simply jump through the directory structure using
> 'cd' commands. That alway worked fine, but these are the
> ones that are problematic on my present matlab system. Is
> there a simple explanation for this? Or is this just a
> not-so-good programming practice? I can of course add the
> directory structure to the path when calling the script and
> be done with it (and remove after running), but just like to
> know what's causing the problems that were never there before.
> 
> Thanks,
> 
> Tim
> 
> 
> 
> 
> Gordon Weast <gweast@mathworks.com> wrote in message
> <fd0hqp$4s2$1@fred.mathworks.com>...
> > Tim,
> > 
> > Try executing 'clear functions' at the MATLAB prompt after
> you edit
> > the file.  That will clean out any cached versions of m files.
> > 
> > If you create a new file and put it down in the
> MATLABROOT/toolbox/...
> > tree somewhere, then you need to rehash or the file won't
> be found.
> > 
> > Gordon Weast
> > xPC Target Development
> > The MathWorks
> > 
> > Tim wrote:
> > > Weird question. Running Matlab r2006a on  a 64bit linux
> > > system I ran into the following. Whenever I change something
> > > in an m-file, the first time I then call it from the command
> > > window it will not include the changes just made. I will
> > > need to run it again, to have it updated. 
> > > 
> > > This is not only a hassle but also very problematic when
> > > checking for bugs, or developing code in general. I never
> > > had this before (I've ran various Matlab versions on both
> > > windows, linux and unix over the last years) and I'm pretty
> > > much clueless as to where this might be coming from.
> > > 
> > > Thanks for any input!
>