# Trouble reading numerical data out of a MAT file

**URL:** https://discourse.julialang.org/t/trouble-reading-numerical-data-out-of-a-mat-file/75052
**Category:** General Usage
**Tags:** question
**Created:** [January 23, 2022, 2:04am UTC](https://discourse.julialang.org/t/trouble-reading-numerical-data-out-of-a-mat-file/75052 "2022-01-23T02:04:57Z")
**Posts on this page:** 3
**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: [January 23, 2022, 2:04am UTC](https://discourse.julialang.org/t/trouble-reading-numerical-data-out-of-a-mat-file/75052/1 "2022-01-23T02:04:57Z")

</div>

I have a mat file that was created using Julia. It contains a variable `T` that stores a 360x180 matrix of numerical values that was generated using `DIVAnd.jl`. I can read the values out using Matlab without any hiccup at all.

Here is the code to read the mat file:

```julia
# Read values out of the mat file:
using MAT;
F1 = "path/test.mat";
T = read(F1, "T");
close(F1);

```

Here are the errors I got when trying to open it using Julia:

```julia
ERROR: LoadError: MethodError: no method matching read(::IOStream, ::String)
Closest candidates are:
  read(::Union{HDF5.File, HDF5.Group}, ::AbstractString; pv...) at ~/.julia/packages/HDF5/pIJra/src/HDF5.jl:1159
  read(::AbstractString, ::Any...) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/io.jl:434
  read(::MAT.MAT_v5.Matlabv5File, ::String) at ~/.julia/packages/MAT/f523T/src/MAT_v5.jl:407
  ...
Stacktrace:
 [1] (::Base.var"#362#363"{Tuple{String}})(io::IOStream)
   @ Base ./io.jl:434
 [2] open(f::Base.var"#362#363"{Tuple{String}}, args::String; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Base ./io.jl:330
 [3] open(f::Function, args::String)
   @ Base ./io.jl:328
 [4] read(filename::String, args::String)
   @ Base ./io.jl:434
 [5] top-level scope

```

Here is how the mat file was created:

```julia
matwrite(F3, Dict(
"T" => T,
"S" => S
); compress = true)

```

Many thanks!

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [January 23, 2022, 2:19am UTC](https://discourse.julialang.org/t/trouble-reading-numerical-data-out-of-a-mat-file/75052/2 "2022-01-23T02:19:49Z")

</div>

[https://github.com/JuliaIO/MAT.jl](https://github.com/JuliaIO/MAT.jl)

it looks like the usage should be:

```julia
using MAT;
F1 = matopen("path/test.mat")
T = read(F1, "T")
close(F1)

```

your original code doesn’t make sense because you’re `close()`ing a string and you don’t need to / can’t do that.

---

<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: [January 23, 2022, 2:39am UTC](https://discourse.julialang.org/t/trouble-reading-numerical-data-out-of-a-mat-file/75052/3 "2022-01-23T02:39:22Z")

</div>

Many thanks! It is working great now.

Can’t imagine I made that mistake.
