Problems updating variables from java generated m-files

1 view (last 30 days)
Josef Thingnes
Josef Thingnes on 1 May 2011
To analyse the output of one program, I have written a Java program that reads the output and write it to a series of m-files that contain two variables each.
In Matlab I read each series of m-files and plot it to visualize the data.
My problem is that Matlab are keeping old versions of the variables in stead of updating when reading the files. It gets an old version of the correct variable (from the correct file)
  • I get no error message
  • The file are flushed and closed in Java
  • When I look at the m-files in the Matlab editor, they are indeed updated.
  • If I alter one of the files and save it, Matlab reads the updated version of all the files in that directory.
  • If I restart Matlab, the updated versions of all files are read.
  • I use the 'run' function in Matlab to execute the m-files
  • It seems like Matlab store an old version of the two variables for each file, and does not update from file.
I do not understand this, can anyone help me?

Accepted Answer

Jan
Jan on 1 May 2011
WHile REHASH and CLEAR FUNCTIONS concerns all functions in the PATH and all currently loaded functions, this touchs the specific function only:
clear(FuncName)
with setting FuncName to the name of the created M-files.
Creating M-files is a very inefficient method in Matlab, if you want to provide values. It would be more stable to create a data file in ASCII or binary format.
  1 Comment
Josef Thingnes
Josef Thingnes on 2 May 2011
Thanks a lot!
The clear(FuncName) did the job.
I will make one tabulated data file for each matrix next time!
-Jo

Sign in to comment.

More Answers (2)

Jarrod Rivituso
Jarrod Rivituso on 1 May 2011
Sounds like MATLAB isn't aware a file has changed, and might be using an old, cached version of it.
Two thoughts you might try...
- Have MATLAB refresh function and file system path caches
rehash
- Try to clear all things from memory (rehash might do this automatically, I'm not sure)
clear functions

Henry
Henry on 4 Jul 2012
Thanks! I had this same problem and had just been dealing with it for ages. I just put a clear(mfile) where mfile is the name of the mfile I was reading.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!