ERROR :Unable to read MAT-file. Not a binary MAT-file. Try load -ASCII to read as text. (no octave code)

ERROR :Unable to read MAT-file. Not a binary MAT-file. Try load -ASCII to read as text.
I don't have any octave code and this problem only happened after windows update.
Only part of data cannot be loaded by the matlab but can be opened by other machines.
I have reinstalled Matlab 2021a.

9 Comments

"Only part of data cannot be loaded by the matlab but can be opened by other machines."
What does that mean, precisely? That another installation of ML can read the same .mat files or are doing something different to open the files?
Thank you.
Some .mat files can be loaded but some cannot be loaded by the matlab. These .mat files are all created by the same Matlab version. The .mat files that cannot be loaded were recently opened by the Matlab.
I copied these problematic .mat files to another computer with Matlab 2019a. The data can then be opened. I used the same command,"load", in both machines.
@Jipeng Yan: please upload a file that you cannot open, by clicking the paperclip button.
If you can open them on another machine, then try to re-SAVE the variables in another file so you don't lose the one you have and then try the new copies on the original machine.
If this works, somehow there's something corrupted on the one; what would be different given the Windows update might be some one of the system DLLs that is used deep in the bowels of the system.
You might try seeing if you can rollback the last Windows update and if that would restore functionality.
If checksums for the files are the same, sometimes just "there be gremlins" and somethings are never able to be fully explained just what may have happened...perhaps a power glitch with a file open altho that would seem unlikely if the file can be copied and then opened on the other machine.
Hi, dpb. Thank you very much.
I tried your suggestion. If resaving the file as -v7, it workes. If resaving the file as -v7.3, it doesn't work. I set the saving format of the matlab on original machine to -v7.3.
Are these files being saved across/on a network by any chance?
If so, if they're all local copies instead does it make any difference?
I copy files by the remote desktop application. Files were saved locally.
It is a valid MAT file, and the current MATLAB version has no problem LOADing it:
S = load('roi_para.mat')
S = struct with fields:
bw_mask_pre: [271x371 double] x_axis_roi: [0 1.6369e-05 3.2737e-05 4.9106e-05 6.5474e-05 8.1843e-05 9.8211e-05 1.1458e-04 1.3095e-04 1.4732e-04 1.6369e-04 1.8005e-04 1.9642e-04 ... ] (1x660 double) x_axis_super: [4.0921e-06 8.1843e-06 1.2276e-05 1.6369e-05 2.0461e-05 2.4553e-05 2.8645e-05 3.2737e-05 3.6829e-05 4.0921e-05 4.5013e-05 4.9106e-05 ... ] (1x2637 double) z_axis_roi: [8.1843e-04 8.3479e-04 8.5116e-04 8.6753e-04 8.8390e-04 9.0027e-04 9.1664e-04 9.3300e-04 9.4937e-04 9.6574e-04 9.8211e-04 9.9848e-04 0.0010 ... ] (1x452 double) z_axis_super: [8.2252e-04 8.2661e-04 8.3070e-04 8.3479e-04 8.3889e-04 8.4298e-04 8.4707e-04 8.5116e-04 8.5525e-04 8.5935e-04 8.6344e-04 8.6753e-04 ... ] (1x1805 double)

Sign in to comment.

Answers (1)

It seems you are encountering an error because the file you are trying to load is not a proper MAT file. To verify if a file is indeed a proper MAT file, you can open it with a text editor like Notepad++ on Windows. Despite MAT files being binary and mostly not human-readable, the first line should always be in plain text. This line typically looks something like this:
MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Jul 13 19:17:35 2022
If this initial line of text is missing, it's likely the file is not a proper MAT file. It's important to note that while files with a ".mat" extension are expected to be MAT files, they might not always adhere to the proper format. MATLAB supports various MAT file formats, and all are binary.
When attempting to load a MAT file into the workspace, you might use the following command:
load('-ASCII', <Filename>)
Ensure that the file is a proper MAT file to avoid errors.

Categories

Products

Release

R2021a

Asked:

on 4 Jul 2021

Commented:

on 15 Jan 2025

Community Treasure Hunt

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

Start Hunting!