"Unable to read MAT-file" shared resources between MATLAB instances
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 26 Juin 2017
Réponse apportée : MathWorks Support Team
le 7 Juil 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?
Réponse acceptée
MathWorks Support Team
le 26 Juin 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!