Can not open this MAT file

I have two MAT files. I can open A but can not open B.

When I used the command “@show(File)”. I got the below for A:
F1 = MAT.MAT_HDF5.MatlabHDF5File(HDF5.File: (read-only) /Volumes/A.mat, true, false, 1108, false)

but the below for B:
F2 = MAT.MAT_v5.Matlabv5File(IOStream(<file /Volumes/B.mat>), false, undef)

What is wrong with my file B?

File A was created by someone I do not know, and File B was created by myself using the command below:
save(File_W, ‘Variable1’, ‘Variable2’);

I can open File B in Matlab easily.

It’s been a long time since I looked at MAT.jl and MATLAB files in general, but IIRC the v5 file format is quite old and the file reader in MAT.jl for that format is incomplete. As such, it’s possible to save objects in that format that can’t be read by MAT.jl.

You are better off saving it in the newer HDF5-based MATLAB format as that’s much better supported.

1 Like

Many thanks for the reply. I’ll try to figure out how to create HDF-5 based MAT files.

What you’ve posted isn’t necessarily evidence of trouble. I think the #undef is to be expected. What do you get from keys(F2)?

1 Like

The “version” option in MATLAB save has default value “-v7” which should do.
Just read File A in MATLAB and resave it

I got a list of all the variables by trying @show(keys(F2)):
keys(F2) = ["Variable1", "Variable2", ..., ""].

There is just one problem. I have one Variable10, which is a string array. In my keys function, this variable is not displayed. Instead I only see an empty variable like "",

Variable10 = 

  6×1 string array

    "32WC20110812"
    "33HH20180625"
    "33HQ20080703"
    "33RO20120721"
    "33RO20160505"
    "33RO20170718"

Thank you. Yes , ‘-v7.3’ works. However, I now have a very weird situation. “Variable10” now shows up properly in the keys function output. However, when I tried to read the value out

Var10 = read(F2, "Variable10");
@show(Var10)

Julia shows

Var10 = missing

**┌ Warning:** MATLAB string values are currently not supported

**└** @ MAT.MAT_HDF5 ~/.julia/packages/MAT/mUpW6/src/MAT_HDF5.jl:169

On the other hand, File A does not have that issue at all. Here is the Variable10 in File A:
EXPOCODE = Any["06AQ19840719"; "76XL20080730"; "77DN20210725";;]

I did further investigation and found that in File A, the strings were stored as cell array. It seems that the MAT package can only handle cell array but not so much on string arrays.

For future reference, below was what I did in Matlab to make it work:
Var10 = cellstr(Var10);