How to deal with corrupted matlabprefs?
Show older comments
I run a matlab-script that use batch processing to collect sample from different sensors at same time.
Some sensors are connect using UDP protocol, modbus, and serial port.
As a rule, they work fine. However, sometimes I have an error related to matlabprefs.mat.
As a consequence, one of the sensors can stop to collect data, i.e., I can not read correctly form a specific serial port, and in the next time I run the same matlab script, it will fail producing some complaining about "matlabprefs.mat" (see example below).
I have this problem frequently.
I am affraid becasue If I can not deal properlly with this problem,I can not trust on matlab to control my data sample system.
Please, could you help me to figure out a deffinitive solution for this issue?
Warning: Initializing MATLAB Graphics failed.
This indicates a potentially serious problem in your MATLAB setup, which should be resolved as soon as possible. Error detected was:
MATLAB:load:unableToReadMatFile
Unable to read MAT-file C:\Users\user\AppData\Roaming\MathWorks\MATLAB\R2023a\matlabprefs.mat. File might be corrupt.
> In hgrc (line 151)
In matlab.graphics.internal.initialize (line 15)
9 Comments
Steven Lord
on 19 Aug 2024
Are multiple files (running in parallel, using Parallel Computing Toolbox or some other mechanism) trying to modify the preferences or the settings simultaneously? If so we're going to need to see those files and know more about how you run them in parallel to be able to suggest how to avoid the file contention. If you don't feel comfortable posting that code on MATLAB Answers you could contact Technical Support directly using this link and ask them to help you determine what's causing the contention and how to avoid it.
You also said "As a consequence, one of the sensors can stop to collect data, i.e., I can not read correctly form a specific serial port, and in the next time I run the same matlab script," after an error. What is the full and exact text of that error message (all the text displayed in red in the Command Window)? If there are any warning messages (displayed in orange) please show those as well.
Steven Lord
on 20 Aug 2024
Nothing of what you've showed jumps out at me as obviously something that could corrupt the preferences, but there is a lot of information that you haven't shown us. Given how much back-and-forth debugging I think this is likely to require you should probably contact Technical Support and work with them to determine the cause of the corruption. Send them a link to this MATLAB Answers thread as well as the contents of the MissMie_sensor_selector and sample_continuous_MissMie functions (plus whatever they'd need to run those two functions.)
Steven Lord
on 22 Aug 2024
Okay, now that you know what happened to corrupt the preferences, please work with Technical Support so they can help you determine how to avoid or work around the problem (and can report it to the development staff to be fixed.)
LucasBar
on 22 Aug 2024
Steven Lord
on 22 Aug 2024
I don't know. It's a bug somewhere (in the parallel code, in the serial port code, in the preference handling code, or perhaps somewhere else.) Without reproduction steps it's going to be difficult or impossible to isolate it and offer a workaround and/or a solution. That's why I recommend contacting Technical Support.
Walter Roberson
on 23 Aug 2024
It does not solve the Matlab problem. It can affect many other users, that can migrate to python to avoid it. Now, we are doing it. We are migrating our system to python until this issue are not solved. I am a old matlab user, I love matlab, however, it was a decision of my supervisor. The problem is simple: serial port errors in the batch cause the corruption of matlabprefs.mat.
Walter Roberson
on 23 Aug 2024
What you are asking about happens to be beyond the experience of @Steven Lord . Steven Lord happens to work for Mathworks, but when he posts here, he posts as a volunteer. He is recommending that you contact Mathworks Technical Support.
LucasBar
on 23 Aug 2024
Accepted Answer
More Answers (1)
Categories
Find more on MATLAB Compiler SDK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!