필터 지우기
필터 지우기

Copy file and immediately read in content

조회 수: 3 (최근 30일)
Tintin Milou
Tintin Milou 2022년 9월 7일
댓글: dpb 2022년 9월 7일
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
dpb
dpb 2022년 9월 7일
@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.

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 9월 7일
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개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by