Why do I get this error when loading a Matlab created file?

조회 수: 26 (최근 30일)
Brianna Miranda
Brianna Miranda 2022년 5월 1일
답변: Krishna 2022년 8월 26일
This is the full error message that I am receiving. I created these files in matlab and when I try to load them I get the following error message:
Error using load
Unable to read MAT-file /Users/........./Vs.mat. Not a binary MAT-file. Try load -ASCII to read as
text.
I tried using load('Vs.mat','-ascii') but this creates a blank vector and I am trying to load a vector.
  댓글 수: 3
Voss
Voss 2022년 5월 1일
Can you upload one of the mat files that gives you this error? (Upload a file using the paperclip button.)
dpb
dpb 2022년 5월 1일
편집: dpb 2022년 5월 1일
Probably get same/similar error, but for grins what does
whos -file Vs
return?
Can you create/read (save/load) a new .mat file now successfully?
It does seem like every once in a while for no explicable reason a .mat file does get corrupted in my experience but there's never been any time where could reproduce a symptom in order to be able to file bug report.
Just for confirmation, if the .mat file was created interactively from the command line, can you recall from the commandhistory the specific command used to create it? If was from a script or in a function or used the GUI interface, this will be a non-starter, but occasionally can use the command history and recover after a user error.

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

답변 (1개)

Krishna
Krishna 2022년 8월 26일
I understand that you are facing issue while running matlab files. 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.
I hope this solves your issue.

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by