"Unable to read MAT-file" shared resources between MATLAB instances
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 26 Giu 2017
Risposto: MathWorks Support Team
il 7 Lug 2017
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?
Risposta accettata
MathWorks Support Team
il 26 Giu 2017
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Workspace Variables and MAT Files 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!