"Unable to read MAT-file" shared resources between MATLAB instances
조회 수: 12 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2017년 6월 26일
답변: MathWorks Support Team
2017년 7월 7일
I have two instances of MATLAB running. The first instance is collecting data and saving it to a MAT-file. It collects data at a fixed interval and saves it to the .mat file after collecting a certain amount of data. The second instance is doing some calculations on the same MAT-file data. It is importing the data using the "matfile" command. The second file is running every few minutes.
Every so often I get the following error:
"Unable to read MAT-file C:\dataFile.mat. Try load -ASCII to read as text."
Later I am able to load that same MAT-file in MATLAB manually, or restart the script with no issues. This does not happen all the time and appears to be sporadic.
Any ideas what might be causing this?
채택된 답변
MathWorks Support Team
2017년 6월 26일
One reason you may be receiving the error "Unable to read MAT-file" is because multiple instances of MATLAB running on the same machine are not inherently synchronized when accessing shared resources. If two instances of MATLAB are accessing the same data, there is a chance the data may become corrupted.
A possible workaround for this issue would be to create a "lock" file for each instance of MATLAB, and before performing any operations on the data, check to ensure the other instance's "lock" file doesn't exist. This would indicate if it is safe to read or write to that MAT-file.Attached is a pair of files, "writer.m" and "reader.m". These files demonstrate one possible workflow for creating these "lock" files.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!