Converting MATLAB ".mat" matrices to julia matrices

Note that A.mat is a file in “MAT” format, and not a matrix. In MATLAB, if you do

>> vars = load("A.mat")

you get a MATLAB struct containing the variables you saved. If the A.mat file contains a matrix A, then you can access it in MATLAB with

>> A = vars.A % or directly with A = load("A.mat").A

In Julia, you would do

julia> A = vars["A"] # or directly A = matread("A.mat")["A"]

That’s because MATLAB’s structs are essentially the same as Julia dictionaries, albeit with the syntactic difference to grab objects inside (i.e., vars.A in MATLAB vs vars["A"] in Julia).

3 Likes