Dictionary Issue when using MAT.jl

Hi Everyone,

I am new to Julia and I was trying to convert some MATLAB code to Julia. The code I am converting uses .MAT file ( a MATLAB file to store workspace variables). In order to load this .MAT file I am using MAT.jl.

I am able to read the .MAT file using MAT.jl however the key value pair I get after reading the file is not what I expected. I have attached the respective output I get when reading the key values pairs.

I am unable to access the respective values for the keys I am getting.
Any help in this matter would be appreciated, thanks.

values is probably not what you want. Try just accessing that field of the struct directly with index notation, i.e.


Also, welcome! You may also consider joining the #matlabsconders channel on slack or zulip

Hi brenhinkeller,

Thanks for your quick response! I tried to access the dictionary using the square bracket notation, however when I enter the respective key in the square brackets I get this error:

I have also attached the structure of the dictionary if it helps (sorry if it is difficult to read, the cell output was very large hence I had to zoom out):

Thanks for your help again!

Ah, I’ve just noticed you’re using matopen (which I actually didn’t know existed). I’ve always used matread instead, which is what my advice above would apply to.

For reference, the built-in documentation (type ? at the REPL) is pretty good here:

help?> matread
search: matread matwrite

  matread(filename) -> Dict

  Return a dictionary of all the variables and values in a Matlab file, opening and
  closing it automatically.


help?> matopen
search: matopen

  matopen(filename [, mode]; compress = false) -> handle
  matopen(f::Function, filename [, mode]; compress = false) -> f(handle)

  Mode defaults to "r" for read. It can also be "w" for write, or "r+" for read or write
  without creation or truncation.

  Compression on reading is detected/handled automatically; the compress keyword
  argument only affects write operations.

  Use with read, write, close, keys, and haskey.
  read(matfile_handle, varname) -> value

  Read a variable from an opened Matlab file and return its value.

  See matopen and matread.

It worked when using matread, instead of matopen. I should have gone through the documentation better.
Thanks a lot for your help, I was stuck on this for way too long!

1 Like

Glad to help!