Copy file and immediately read in content

4 visualizaciones (últimos 30 días)
Tintin Milou
Tintin Milou el 7 de Sept. de 2022
Comentada: dpb el 7 de Sept. de 2022
Hello,
I have a file that defines parameter values that, at the beginning of the algorithm, I copy into a 'temporary' folder.
Later on in the algorithm, I read this file from the temporary folder to get the parameter values.
For some reason, matlab doesn't copy fast enough in the sense that it doesn't read in the parameter values from the new parameter file, but from the one that was sitting in the temp folder before.
So far, I have always manually interrupted the code at the beginning and then re-ran it to make sure that the parameter file in the temp folder is properly updated. I've tried to put a 'pause' statement after copying to give matlab some time, but that doesn't seem to work.
Thanks for your help!
  1 comentario
dpb
dpb el 7 de Sept. de 2022
@Fangjun Jiang has the answer that will solve the problem with the temporary file but...
If you're building the content of the file dynamically, instead of using a file for data transfer, why not construct your code to be able to pass that content (as array, stuct, table...) to a function that consumes it instead? That would probablly just entail refactoring the part of the code that reads the file into a function to accept the new data structure.
You can still keep the file for archival purposes, but seems like probably could dispense with for the actual first-time use as described.

Iniciar sesión para comentar.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 7 de Sept. de 2022
In your script, try adding "rehash" after the line where the file is copied.
doc rehash
Use rehash with no arguments only when you run a program file that updates another program file, and the calling file needs to use the updated version of the second file before the calling file has finished running.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by