Thread Subject: M files must be run twice for changes to take effect on linux system

Subject: M files must be run twice for changes to take effect on linux system

From: Tim

Date: 20 Sep, 2007 20:28:24

Message: 1 of 8

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!

Subject: M files must be run twice for changes to take effect on linux system

From: Dan Haeg

Date: 20 Sep, 2007 22:38:07

Message: 2 of 8

"Tim " <timtjanssen@yahoo.com> wrote in message
<fcul58$kac$1@fred.mathworks.com>...
> 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!

I ran into a similar problem on windows. I wrote a function
that writes a script using fprintf. The last line in the
function runs the script which has been closed with fclose.
It does not run the current version of the script though. If
I run the script from the command line the current one gets run.

Subject: M files must be run twice for changes to take effect on linux system

From: Malcolm Lidierth

Date: 21 Sep, 2007 12:36:41

Message: 3 of 8

Have you tried:
>>clear functionname
Also see help inmem

Is the fucntion a callback?

Subject: M files must be run twice for changes to take effect on linux

From: Gordon Weast

Date: 21 Sep, 2007 13:43:53

Message: 4 of 8

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!

Subject: M files must be run twice for changes to take effect on linux

From: Tim

Date: 1 Dec, 2007 05:23:29

Message: 5 of 8

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!

Subject: M files must be run twice for changes to take effect on linux

From: Seth

Date: 2 Mar, 2009 15:09:01

Message: 6 of 8

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!
>

Subject: M files must be run twice for changes to take effect on linux

From: Steven Lord

Date: 2 Mar, 2009 16:08:05

Message: 7 of 8


"Seth " <neologism+matlab@gmail.com> wrote in message
news:gogsqd$pbe$1@fred.mathworks.com...
>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.

Where did you save this M-file? If you saved it in a directory under
$MATLABROOT/toolbox, then we strongly recommend you save it elsewhere.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/f8-28521.html

If you didn't save it under the toolbox directory, did you save it on a
network drive? If the network drive doesn't inform MATLAB that the file has
changed promptly (or at all), MATLAB may not learn that the function has
changed until you clear it from memory, at which time MATLAB has to ask the
network drive for a new copy of the function to load into memory.

--
Steve Lord
slord@mathworks.com

Subject: M files must be run twice for changes to take effect on linux

From: Seth

Date: 30 Mar, 2009 03:53:01

Message: 8 of 8

No, I saved it in a local directory, outside of any of the MATLAB (or my personal) paths. The exact path was something like '/Users/seth/_code/imc/suolson.m'; the file essentially creates a bunch of variables in the local workspace. Calling
run('/Users/seth/_code/imc/suolson.m')
would work the first time after 'clear functions' or after launching MATLAB. However, calling 'run' again, after the data had been changed outside of MATLAB, did nothing. Even after I opened it in MATLAB's editor and pressed the 'run' button used the contents of the file before it had been modified. (I deleted the local workspace variables before doing this, just to make sure it actually was running.)

With the previously mentioned workarounds, and with my beginning to transition to other data analysis and plotting utilities, the issue is less important to me now.

Thanks,
Seth

"Steven Lord" <slord@mathworks.com> wrote in message <goh095$dlk$1@fred.mathworks.com>...
>
>
> Where did you save this M-file? If you saved it in a directory under
> $MATLABROOT/toolbox, then we strongly recommend you save it elsewhere.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/f8-28521.html
>
> If you didn't save it under the toolbox directory, did you save it on a
> network drive? If the network drive doesn't inform MATLAB that the file has
> changed promptly (or at all), MATLAB may not learn that the function has
> changed until you clear it from memory, at which time MATLAB has to ask the
> network drive for a new copy of the function to load into memory.
>
> --
> Steve Lord
> slord@mathworks.com
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com