# Can not open this MAT file

**URL:** <https://discourse.julialang.org/t/can-not-open-this-mat-file/130215>\
**Category:** General Usage\
**Created:** [June 25, 2025, 10:19pm UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215 "2025-06-25T22:19:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [June 25, 2025, 10:19pm UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215/1 "2025-06-25T22:19:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [June 25, 2025, 10:37pm UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215/2 "2025-06-25T22:37:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [June 25, 2025, 11:38pm UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215/3 "2025-06-25T23:38:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [June 25, 2025, 11:51pm UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215/4 "2025-06-25T23:51:05Z")

</div>

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)`?

---

<div class="post-metadata">

**Author:** ![pitsianis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pitsianis/32/26588_2.png) [@pitsianis](https://discourse.julialang.org/u/pitsianis)\
**Post date:** [June 26, 2025, 12:20am UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215/5 "2025-06-26T00:20:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [June 26, 2025, 12:24am UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215/6 "2025-06-26T00:24:20Z")

</div>

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 `"",`

```julia
Variable10 = 

  6×1 string array

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

```

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [June 26, 2025, 1:14am UTC](https://discourse.julialang.org/t/can-not-open-this-mat-file/130215/7 "2025-06-26T01:14:33Z")

</div>

> [@pitsianis](#):
>
> “-v7”

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

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

```

Julia shows

```julia
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);`
