Copy file and immediately read in content
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
dpb
il 7 Set 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.
Risposta accettata
Fangjun Jiang
il 7 Set 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.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!