Problems updating variables from java generated m-files

1 Ansicht (letzte 30 Tage)
Josef Thingnes
Josef Thingnes am 1 Mai 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?

Akzeptierte Antwort

Jan
Jan am 1 Mai 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 Kommentar
Josef Thingnes
Josef Thingnes am 2 Mai 2011
Thanks a lot!
The clear(FuncName) did the job.
I will make one tabulated data file for each matrix next time!
-Jo

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Jarrod Rivituso
Jarrod Rivituso am 1 Mai 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 am 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.

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by