Reading and Writing mat Files in Julia
Overview
MAT.jl
is a library for reading and writing *.mat
files, which are the data storage format used in MATLAB1. As is typical of Julia, this package does not force users to abandon their existing programming languages and habits; instead, it aims to secure users by providing an environment that is as familiar as possible.
- While the speed and convenience of Julia are significant advantages, MATLAB offers unique benefits for visualization for research purposes. If you are already proficient at drawing with MATLAB, a ‘complete transition to Julia’ may seem less appealing due to the significant sacrifices it entails. The existence of
MAT.jl
presents a tempting proposition: “Don’t worry about that, just perform your calculations quickly with Julia and then go back to MATLAB for drawing.” - Conversely, it is also helpful in situations where ‘you have already done much work and built structures with MATLAB but feel some limitations and wish to switch to Julia’.
To learn about Julia’s advanced native storage format, refer to the JLD2.jl
package.
Code
X = rand(0:9, 8, 3)
using MAT
matwrite("example.mat", Dict("Y" => X))
matfile = matopen("elpmaxe.mat")
A = read(matfile, "A")
close(matfile)
Julia → MATLAB
MATLAB → Julia
Environment
- OS: Windows
- julia: v1.7.3
- MAT v0.10.3
- MATLAB: R2022b